Phonegap: How to use geolocation without GPS in android and enableHighAccuracy: true

I'm using geolocation in my app in but I have a little problem (or question) about how to use it in android without GPS enabled.

Using this code in android it GPS is enabled in the device it works fine, but it the gps is disabled the code give an error (default error in my script)

watchID=navigator.geolocation.getCurrentPosition(handle_geolocation_query, handle_errors, {timeout: 600000, enableHighAccuracy: true});

function handle_errors(error)
        case error.PERMISSION_DENIED: window.localStorage.setItem("geo_aviso", "latitud", position.coords.latitude);

        case error.POSITION_UNAVAILABLE: window.localStorage.setItem("geo_aviso", "No podemos encontrar localizaión verifica que la tienes activada en tu dispositivo");

        case error.TIMEOUT: window.localStorage.setItem("geo_aviso", "Tiempo de espera agotado para encontrar tu localización vuelve a entrar en la app");

        default: window.localStorage.setItem("geo_aviso", "No podemos detectar tu localización, comprueba que tienes el GPS activado en tu dispositivo");

function handle_geolocation_query(position){
    if (position.coords.latitude!=null)
        some code here

If I use the same code without enableHighAccuracy: true gives the geolocation in both situations (with and without gps enabled) but GPS never is used.

Is that the expected result or shall I have to use a diferent code?

Another issue is that when GPS is avaliable but the app can't get a location (if your are not in open air) no location is given (It must give the location based on the mobile network or wifi)

Tested in android: 4.3 (HTC One)


That definately seems like the expected result to me. What is happening is your device behind the scenes is smart enough to cycle through all the ways it can get its current location from most to least accurate.

  1. GPS
  2. wifi location(location of nearest access point)
  3. cell tower location(known location of cell tower you are currently connected to)

If you disable gps location, the device will keep going down this list until it gets to a location method that works. You can most easily tell this by looking at the "accuracy" attribute return with the position object. In my experience an accuracy < 100 indicates gps location, < 1000 indicates wifi location, above that you are definately on cell tower based location. These are of course just rough guidlines, depending on line of sight to a satellite and availability of wifi/cell towers the the accuracy could differ a great deal. The point is disabling gps doesn't stop you from getting a location it just forces the phone to use less precise methods.

Need Your Help

NodeJS - inner dynamic templates in EJS Template engine

templates node.js ejs

I'd like to create an inner dynamic template for menu header. I'd like to send parameter of current page for my inner menu template, located in main page template, and depending on url, it should s...

How to Retrieve Facebook Life Events for a User

javascript facebook facebook-graph-api

Is there a way to retrieve the Life Events of an authenticated Facebook User using the Graph API? It seems like this is simple to do for a Page, but I can't seem to find a way to retrieve a list of...