2017-03-06 6 views
0

私はswiftを使用して地図を作成しています。 Appleマップに保存されている現在の場所の名前を見つけるにはどうしたらいいですか?私はWalmartにいると言います。場所の名前を印刷するにはどうしたらいいですか?ロケーション名のスウィフトマップを見つける

私の現在のコードは、あなたが名前を配置するために経度と緯度を変換するために、iOSのネイティブAPIを使用することができます

class MapVC: UIViewController, CLLocationManagerDelegate { 

@IBOutlet weak var map: MKMapView! 

let manager = CLLocationManager() 


func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 

    let location = locations[0] 
    let span:MKCoordinateSpan = MKCoordinateSpanMake(0.01, 0.01) 

    let mylocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude) 
    let region:MKCoordinateRegion = MKCoordinateRegionMake(mylocation, span) 
    map.setRegion(region, animated: true) 

    print(location.coordinate) 
    print(location.coordinate.latitude) 
    print(location.speed) 

    self.map.showsUserLocation = true 
    self.map.showsPointsOfInterest = true 


} 

override func viewDidLoad() { 
    super.viewDidLoad() 

    manager.delegate = self 
    manager.desiredAccuracy = kCLLocationAccuracyBest 
    manager.requestAlwaysAuthorization() 
    manager.startUpdatingLocation() 

} 
+0

[都市名への座標変換?](https://stackoverflow.com/questions/27735835/convert-coordinates-to-city-name) – Emm

答えて

-1

です:たとえば

func reverseGeocodeLocation(_ location: CLLocation, 
      completionHandler: @escaping CLGeocodeCompletionHandler) 

を:

var geocoder = CLGeocoder() 
geocoder.reverseGeocodeLocation(location, completionHandler: {(placemarks, error)->Void in 

}) 

は場所を取得タイプCLPlacemarkである目印の最初のオブジェクトを取得することによって名前を取得します。その後、CLPlacemarkのnameプロパティは、後になっています。

+0

のように 'placemarks.name'を表示して名前を取得してください –

+0

はい。詳細については、このドキュメントを参照してください。 https://developer.apple.com/reference/corelocation/clplacemark –

関連する問題