測試地址

swift 地址轉經緯度

import MapKit
let geoCoder = CLGeocoder()
geoCoder.geocodeAddressString("台中市南區復興路一段460號", completionHandler: {(placemarks:[CLPlacemark]!,error:Error!) in
    if error != nil{
        print(error!)
        return
    }
    if placemarks != nil && placemarks.count > 0{
        let placemark = placemarks[0] as CLPlacemark
        print("\(placemark.location?.coordinate.latitude ?? 0.0),\(placemark.location?.coordinate.longitude ?? 0.0)")
    }
})
24.116821,120.657723
po placemark
復興路一段460號, 40256台灣台中市南區復興路一段460號 @ <+24.11682100,+120.65772300> +/- 100.00m, region CLCircularRegion (identifier:'<+24.11682100,+120.65772300> radius 70.55', center:<+24.11682100,+120.65772300>, radius:70.55m)

測試Google map網址

http://maps.google.com/?q=經度,緯度

http://maps.google.com/?q=24.11682100,120.65772300

結果

有點小落差 +/- 100.00m
如果要更準要用google的place api換算
但是要錢

Categorized in: