Find city name and country from latitude and longitude in Swift

前端 未结 11 1979
既然无缘
既然无缘 2020-12-12 22:58

I\'m working on application in Swift3 and I have letter problem i can\'t find the answer for it.

How can I know city name and country short names base on latitud

11条回答
  •  余生分开走
    2020-12-12 23:35

    I had also the same issue .You can use this code.

    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))")
    
    
    
    })
    }
    

    Hope this will resolve your problem.

提交回复
热议问题