2016-08-12 79 views
2

拾取放置錯誤操作無法完成。 Places API無法找到用戶的位置。這可能是因爲用戶未允許應用程序訪問位置信息。如何解決它?這可能是因爲用戶未允許應用程序訪問位置信息

+1

允許在瀏覽器中獲取位置信息!你是如何要求他們的?向我們顯示代碼 –

+0

是的,我已經解決了。謝謝。 – Lidalu

回答

1

所以我從你的問題理解,你正試圖獲取用戶目前的位置,但你正在得到上述錯誤。

在iOS中,必須要求用戶訪問用戶當前位置的權限。您可以通過創建一個CLLocationManager實例來請求權限,然後調用適當的方法。無論您想在應用程序運行時還是始終運行時使用位置服務,都可以根據您的要求選擇合適的方法。因此,這裏是你怎麼做:

let locationManager = CLLocationManager() 
// For getting the user permission to use location service when the app is running 
locationManager.requestWhenInUseAuthorization() 
// For getting the user permission to use location service always 
locationManager.requestAlwaysAuthorization() 

之後,一定要適當的鍵添加到Info.plist文件如下:

<key>NSLocationWhenInUseUsageDescription</key> 
<string>Your location is required to show suggestions</string> 

OR

<key>NSLocationAlwaysUsageDescription</key> 
<string>Your location is required to show suggestions</string> 

字符串關鍵是可選的。但它建議包含一個適當的字符串,它描述了您的應用程序想要訪問用戶位置的原因。

+0

爲什麼我們需要使用CLLocationManager,如果我們不需要使用Mapkit,但是Google Pick Place API? – Mamta

相關問題