我在使用模擬器(即使當我通過telnet連接到geo fix
時)和設備上的Geoocation在Android上工作時遇到了麻煩。適用於iOS,WP8和瀏覽器。Phonegap /科爾多瓦地理位置不能在Android上工作
當我使用下面的代碼詢問設備的位置時,我總是得到一個錯誤(在我的情況下,自定義Retrieving your position failed for unknown reason.
與null
錯誤代碼和錯誤消息)。
相關代碼:
successHandler = (position) ->
resolve App.Location.create
lat: position.coords.latitude
lng: position.coords.longitude
errorHandler = (error) ->
error = switch error.code
when 1
App.LocationError.create
message: 'You haven\'t shared your location.'
when 2
App.LocationError.create
message: 'Couldn\'t detect your current location.'
when 3
App.LocationError.create
message: 'Retrieving your position timeouted.'
else
App.LocationError.create
message: 'Retrieving your position failed for unknown reason. Error code: ' + error.code + '. Error message: ' + error.message
reject(error)
options =
maximumAge: Infinity # I also tried with 0
timeout: 60000
enableHighAccuracy: true
navigator.geolocation.getCurrentPosition(successHandler, errorHandler, options)
平臺/安卓/ AndroidManifest.xml中
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
WWW/config.xml文件(以防萬一)
<feature name="Geolocation">
<param name="android-package" value="org.apache.cordova.GeoBroker" />
</feature>
使用科爾多瓦3.1.0 。在Android 4.2上測試。插件已安裝。包含在index.html中的Cordova.js(InAppBrowser等其他插件工作正常)。
$ cordova plugins ls
[ 'org.apache.cordova.console',
'org.apache.cordova.device',
'org.apache.cordova.dialogs',
'org.apache.cordova.geolocation',
'org.apache.cordova.inappbrowser',
'org.apache.cordova.vibration' ]
我很無能。我錯過了什麼嗎?
您是否使用CLI構建您的項目? –
CLI和Phonegap構建。我已經構建了一個簡單的應用程序,其中地理工作,所以今天我會比較什麼是不同的,並更新問題。 – Kreeki
Kreeki有關於此問題的更多更新?你有沒有比較你的構建? – jguffey