Convert coordinates to City name?

后端 未结 9 1197
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:09

    func placePicker(_ viewController: GMSPlacePickerViewController, didPick place: GMSPlace) {
    
        viewController.dismiss(animated: true, completion: nil)
        let geoCoder = CLGeocoder()
        let location = CLLocation(latitude: place.coordinate.latitude, longitude: place.coordinate.longitude)
        geoCoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) -> Void in
    
            // Place details
            var placeMark: CLPlacemark!
            placeMark = placemarks?[0]
    
            // Address dictionary
            print(placeMark.addressDictionary as Any)
       // 
    
        print("Place name \(place.name)")
        print("Place address \(String(describing: place.formattedAddress))")
        print("Place attributions \(String(describing: place.attributions))")
    
    
    
    })
    }
    

    use this code this will resolve the issue.

提交回复
热议问题