geocodeAddressString not working for some addresses
我正在尝试将地址隐蔽为受尊重的纬度和经度值,即地理编码。
根据Google的定义:
What is Geocoding?
Geocoding is the process of converting addresses (like"1600 Amphitheatre Parkway, Mountain View, CA") into geographic coordinates (like latitude 37.423021 and longitude -122.083739), which you can use to place markers or position the map.
我正在使用Swift在iOS中尝试相同的操作。
我的代码工作正常。 但是某些地址并未转换为经纬度值。 我确定我要搜索的地址是100%有效的。
这是我的代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | override func viewDidLoad() { super.viewDidLoad() var address ="Kloten Airport, Switzerland" // This Address not working var geocoder = CLGeocoder() geocoder.geocodeAddressString(address, {(placemarks: [AnyObject]!, error: NSError!) -> Void in if let placemark = placemarks?[0] as? CLPlacemark { let title = ABCreateStringWithAddressDictionary(placemark.addressDictionary, false) println(title); let location = CLLocationCoordinate2D( latitude: placemark.location.coordinate.latitude, longitude: placemark.location.coordinate.longitude ) } }) } |
我尝试对不同的地址进行地理编码,例如
iOS
我认为您期望iOS地理编码的性能与Google的地理编码一样好。 当然不会。
它无法正常工作,因为Apple的地理编码不如Google的地理编码。
明白我的意思,放
Kloten Airport, Sweden
进入iOS Maps应用。 它什么也没有。 将其放入maps.google.com,您会看到机场。