首页 > 解决方案 > CLPlacemark 没有成员“获取”

问题描述

我指的是一个函数来获取用户的位置,代码如下:

func updateLocation(_ userLocation: CLLocation) {
  if (userLocation.horizontalAccuracy > 0) {
    self.locationService.stopUpdatingLocation()
    return
  }

  self.latitude = NSNumber(value: userLocation.coordinate.latitude as Double)
  self.longitude = NSNumber(value: userLocation.coordinate.longitude as Double)

  if !self.geocoder.isGeocoding {
    self.geocoder.reverseGeocodeLocation(userLocation, completionHandler: {(placemarks, error) in
      if let error = error {
        logger.error("reverse geodcode fail: \(error.localizedDescription)")
        return
      }
      if let placemarks = placemarks, placemarks.count > 0 {
        // TODO:
        let onePlacemark = placemarks.get(index: 0)
        self.address = "\(onePlacemark?.administrativeArea,onePlacemark?.subLocality,onePlacemark?.thoroughfare)"
        self.city = (onePlacemark?.administrativeArea!)!
        self.street = (onePlacemark?.thoroughfare!)!
      }
    })
  }
}

在构建项目时,它在这一行抛出了“CLPlacemark has no member 'get'”的内容:

let onePlacemark = placemarks.get(index: 0)

我正在用 swift 4.0 编写项目,并且

import Foundation
import INTULocationManager

已经完成了。

标签: iosswift4

解决方案


推荐阅读