Using navigator.geolocation.getCurrentPosition in WebView on Android 2.0+ (PhoneGap related)

两盒软妹~` 提交于 2019-11-27 19:30:55

I just tried your code on a Nexus One with Android 2.1, and it works fine. Remember that you'll need to add the necessary permissions to your manifest:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

We (the PhoneGap team) have recently released a fix for this. Basically, the problem was that as of Android 2.0, the native WebView now has its own implementation of navigator.geolocation, and thus the PhoneGap bridge for this function was not getting set properly in JavaScript.

Since then, a particular commit has created a workaround for this: we 'proxy' the native navigator.geolocation object to our own definition of this object. This object works well with the PhoneGap framework.

For this fix, see the following commit: http://github.com/phonegap/phonegap-android/commit/5255f632377c36beb0b4d2620940f33b6d02b2c7

joseAndresGomezTovar

This link has the key http://cordova.apache.org/docs/en/2.5.0/cordova_device_device.md.html

I am developing with Android - Phonegap

I added

app/res/xml/config.xml

<plugin name="Device" value="org.apache.cordova.Device" />

app/AndroidManifest.xml

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!