Convert coordinates to City name?

后端 未结 9 1173
Happy的楠姐
Happy的楠姐 2020-12-02 07:41

How to get an address from coordinates using MapKit?

I have this code when long press on the map it gets the coordinates:

func didLongPressMap(sender         


        
9条回答
  •  一向
    一向 (楼主)
    2020-12-02 08:05

    Thanks @Kampai for his answer, I revised a bit so it works with Swift 1.2:

            var geocoder = CLGeocoder()
            var location = CLLocation(latitude: IC.coordinate!.latitude, longitude: IC.coordinate!.longitude)
            geocoder.reverseGeocodeLocation(location) {
                (placemarks, error) -> Void in
                if let placemarks = placemarks as? [CLPlacemark] where placemarks.count > 0 {
                    var placemark = placemarks[0]
                    println(placemark.addressDictionary)
            }
    

    Result:

    [SubLocality: Sydney, Street: 141 Harrington Street, State: NSW, SubThoroughfare: 141, CountryCode: AU, ZIP: 2000, Thoroughfare: Harrington Street, Name: 141 Harrington Street, Country: Australia, FormattedAddressLines: ( "141 Harrington Street", "The Rocks NSW 2000", Australia ), City: The Rocks]

提交回复
热议问题