Find city name and country from latitude and longitude in Swift

前端 未结 11 1958
既然无缘
既然无缘 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:15

    I would recommend integrating Google Maps API with your project. If you do, your task can be achieved using Reverse Geocoding Google provides.

    Furthermore, Google there is Google Maps SDK for IOS development, which is also worth considering.

    UPD: You can do that without integrating maps into your project. Basing on this answer, you can achieve that using http requests to Google API. The request to:

    https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=API_KEY 
    

    would return JSON object with information about the requested place, including country and city name.

    BTW, I highly recommend using Alamofire to make http requests in Swift.

提交回复
热议问题