简体   繁体   English

Phonegap / Cordova地理位置不适用于Android 4.0+,但适用于所有其他平台

[英]Phonegap/Cordova Geolocation Not working on Android 4.0+ but Working on all other platforms

I am using Phonegap version 3.30 with Phonegap build and UI elements provided by Sencha Touch. 我正在使用带有Seng Touch提供的Phonegap构建和UI元素的Phonegap版本3.30。 The app contains a map on the first page, the map is rendered using open street map and leaflet using a sencha touch library https://market.sencha.com/extensions/ext-ux-leafletmap . 该应用程序在第一页上包含一张地图,该地图使用开放式街道地图和使用sencha触摸库https://market.sencha.com/extensions/ext-ux-leafletmap的传单来呈现。

If I set the map not to use the geolocation option which displays your location on the map then the map renders perfectly on all platforms, however when I enable the setting to use geolocation, the map renders perfectly and overlays the current location on all platforms (iOS, Android 2.0) but NOT Android 4.0+. 如果我将地图设置为不使用在地图上显示您的位置的geolocation选项,则地图可以在所有平台上完美呈现,但是当我启用设置以使用geolocation时,地图将完美呈现并覆盖所有平台上的当前位置( iOS,Android 2.0),而不是Android 4.0+。

In fact on Android the map does not render at all which is similar behaviour to how it used to work with incorrect permissions. 实际上,在Android上,地图根本不会渲染,这与以前使用不正确权限进行操作时的行为类似。 I have set the application to use the 3 location permissions via the Config.xml Phonegap geolocation plugin. 我已将应用程序设置为通过Config.xml Phonegap地理位置插件使用3个位置权限。 Here is the link to the Config.xml https://www.dropbox.com/s/c1im3twg21mnxi6/config.xml 这是Config.xml的链接https://www.dropbox.com/s/c1im3twg21mnxi6/config.xml

So to summarise: Android 4.0 only with Geolocation enabled prevents map from rendering, however the map and geolocation works on all other platforms. 总结一下:仅启用了Geolocation的Android 4.0会阻止渲染地图,但是map和geolocation可以在所有其他平台上使用。

Does anyone know what could be causing this? 有谁知道是什么原因造成的? I have no errors being printed to the console and as far as I can the permissions are correct and as it works on Android 2.0 I am completely stumped. 我没有被打印到控制台的错误,据我所知,权限是正确的,并且在Android 2.0上可以正常使用,我完全感到困惑。

Some pictures below demonstrating the issue, please note that Geolocation also works when the app is run on a web browser. 下面的一些图片说明了问题,请注意,当应用程序在网络浏览器上运行时,地理位置也可以使用。

Android Not Loading with Geolocation Enabled Android未启用地理定位加载 Android无法加载地理定位

iOS Loading Correctly with Geolocation iOS通过地理位置正确加载 iOS通过地理位置正确加载

I have solved the problem, this issue happens on Android 4.2, 4.3 and 4.4. 我已经解决了这个问题,这个问题发生在Android 4.2、4.3和4.4上。

You have to explicitly enable the following options inside your call to Ext.util.geolocation. 您必须在对Ext.util.geolocation的调用中显式启用以下选项。 Allow High Accuracy and Frequency. 允许高精度和高频率。 This has been a massive headache @Sencha please make this simple. @Sencha令人非常头疼,请简单点说。

var geo = Ext.create('Ext.util.Geolocation', {
        autoUpdate: false,
        allowHighAccuracy: true,
        frequency: '3000',
        listeners: {
            locationupdate: function(geo) {
                var currentLat = geo.getLatitude();
                var currentLng =  geo.getLongitude();
                var altitude = geo.getAltitude();
                var speed = geo.getSpeed();
                var heading= geo.getHeading();

// Ext.Msg.alert('Latitude Longitude' + currentLat + currentLng); // Ext.Msg.alert('纬度经度'+ currentLat + currentLng); }, locationerror: function(geo, bTimeout, bPermissionDenied, bLocationUnavailable, message) { if(bTimeout) { // Ext.Msg.alert('Timeout occurred',"Could not get current position"); },locationerror:function(geo,bTimeout,bPermissionDenied,bLocationUnavailable,message){if(bTimeout){// Ext.Msg.alert('发生超时',“无法获取当前位置”); } else { // alert('Error occurred.'); } else {// alert('发生错误。'); } } } }); }}}}); geo.updateLocation(); geo.updateLocation();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM