Search code examples
cordovagpsgeolocationphonegap-plugins

Can I control what types of Geolocation service types (Wifi, GPS, Cell Triangulation) I use in PhoneGap with application logic?


I am trying to determine if I can allow an application to intelligently decide when to use certain location services at the hardware level based on context. For example, if they have been inside (and out of GPS coverage for 5 minutes), it would be nice to poll wifi instead as GPS polling when out of coverage could cause a significant battery drain as I plan to be frequently checking for fine grain location. The application will need to use a PhoneGap API or a plain external JavaScript library if one has cross platform to native sensors.


Here are other sources that I have looked at, including the documentation, but they don't seem to address my question.

PhoneGap geolocator using WiFi instead of GPS

PhoneGap Location Documentation: http://docs.phonegap.com/en/edge/cordova_geolocation_geolocation.md.html

W3C Geolocation API Spec: http://dev.w3.org/geo/api/spec-source.html#api_description

Many thanks in advance!


Solution

  • No, you can't, the only thing you can do is use the enableHighAccuracy option

    enableHighAccuracy: Provides a hint that the application needs the best possible results. By default, the device attempts to retrieve a Position using network-based methods. Setting this property to true tells the framework to use more accurate methods, such as satellite positioning. (Boolean)

    var watchID = navigator.geolocation.watchPosition(onSuccess, onError, { enableHighAccuracy: true });