簡體   English   中英

將mapkit設置為僅具有城市名稱的位置

[英]Set mapkit to location with only a cityname

我從api獲取數據。 此數據僅包含城市名稱。 我想向用戶顯示城市的地圖視圖。

有誰知道如何做到這一點? 我發現了有關CLGeocoder API的一些信息,這有幫助嗎? 還是我應該在歐羅巴的城市中找到帶有緯度和經度的數據庫?

您可以使用geocodeAddressString方法將正向地理編碼與CLGeocoder一起使用。 有關更多信息, 訪問: https : //developer.apple.com/library/prerelease/ios/documentation/CoreLocation/Reference/CLGeocoder_class/index.html#//apple_ref/occ/instm/CLGeocoder/geocodeAddressString : completionHandler

或者,您也可以使用Google Maps服務。

您可以使用Google Geocoding API獲取地址的緯度和經度。

https://maps.googleapis.com/maps/api/geocode/json?address=Newyork&key=PROVIDE_YOUR_API_KEY

您必須在developer.google.com上注冊API_KEY的位置

這將返回JSON格式,您可以在其中解析並獲得最接近的緯度和經度。

有關更多詳細信息,請檢查此鏈接https://developers.google.com/maps/documentation/geocoding/

將緯度和經度分配到CLLocationCoordinate2D中,然后使用標記/注釋在地圖中添加位置

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM