3

I am building a mobile site that needs to fetch high accuracy location from the user's phone. I using the HTML5 Geolocation .watchPosition function and enableHighAccuracy: true.

When tested on IOS devices, The code forces GPS to turn on and return me high accuracy data (4m), but when I tried with my MotoX (kitkat) and Nexus 5, Location symbol does not appear at the phone top bar and the accuracy returned was low (100m).

Something I have also noticed is that even the www.maps.google.com cannot initialize my phone's GPS (uses only inferred location from wifi+network), although all native apps (including Google Maps App) can use it and my phone's location mode is set to "High Accuracy".

I have tested this on the following Android browsers with wifi on and off and had the same result: -Chrome, -Opera Classic -Opera -Dolphin

My JS conde:

navigator.geolocation.watchPosition(success,fail,
        { enableHighAccuracy: true,
         //timeout: 100000,
        //maximumAge: 0 
        });

and the success function is:

function success(pos) {// Location was found
        //set global variables with coordinates
        globalLat=pos.coords.latitude;
        globalLng=pos.coords.longitude;
        $("#precision").html=pos.coords.accuracy;
        alert(pos.coords.accuracy);
        //create google location from coordinates
        latlng=new google.maps.LatLng(globalLat, globalLng);
        //send location to server and get response every 6 seconds;
        setInterval(function(){SendAndGetLocation();}, 6000);
        //create map or update it's center in case it was already created
        if(googleMap===undefined){
            createMap();
        }else{
            googleMap.setCenter(latlng); 
        }
        //Draw user's location on map
        drawLocalMarker(globalLat, globalLng);
    }

Can anyone think of what might be happening?

Cheers

user3754424
  • 31
  • 1
  • 2

2 Answers2

1

don't be misled by GPS, what i mean is dont assume it's going to give you accurate results, consider the app being tombstoned, or the device going to sleep, in this case the accuracy of the network provider is sometime more accurate, I'm doing similar stuff my self and gave up on High accuracy for these reason

http://www.andygup.net/how-accurate-is-html5-geolocation-really-part-2-mobile-web/ and this http://www.andygup.net/six-most-common-use-cases-for-android-gps/

fuzzybear
  • 2,325
  • 3
  • 23
  • 45
  • Thanks Saj, Maybe I should reconsider using high accuracy on my app. Just as an updated, I have just tested on a S2 device running ICS and it Works fine (GPS is forced to activate), so apparently it is a problem with either specific devices or with Kitkat, which avoids the browser to use GPS data. – user3754424 Jun 19 '14 at 19:28
0

Same here, moto x 4.4 with high accuracy html5 geolocation doesnt turn on GPS in chrome. It used to work on older android. When I started app which request gps with android native api html page started getting high precision informations... this is why html5 application has hard time to take off as we can not rely on behavior

Workaround: I will wrap(chromium webview) html5 app/page to native android app and send true geolocation via javascript calls/inter-processing communication.

Exooc Exo
  • 1
  • 1