Thinkerer
Thinkerer

Reputation: 1626

Whats the difference in geolocation in Cordova/HTML 5 versus the Meteor geolocation package?

Im trying to save a user's location when an action is done, so it wont be refreshed constantly. Also looking to do simple calculations with the stored values like distance, speed etc.

From my understanding:

Cordova/HTML 5 geolocation 1. Can set position 2. Asynchronous 3. re-calibrates when a change is detected (needs watch function) 4. Location fields - altitude, accuracy, heading fields also available 5. Works on mobiles and html5 enabled sites (some glitches on ioS)

document.addEventListener("deviceready", onDeviceReady, false);

// device APIs are available
function onDeviceReady() {
    navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
// onSuccess Geolocation
function onSuccess(position) {
    var element = document.getElementById('geolocation');
    element.innerHTML = 'Latitude: '+ position.coords.latitude + '<br />' +
                        'Longitude: '+ position.coords.longitude + '<br />';
}
// onError Callback receives a PositionError object
function onError(error) {
    alert('code: '    + error.code    + '\n' +
          'message: ' + error.message + '\n');
}
//To watch changes 
var watchID = navigator.geolocation.watchPosition(onSuccess, onError, { timeout: 30000 });


mdg:geolocation 1. No current options to set, presumable constantly reactive 2. Easier to do calculations with the location data on the server side 3. Works on mobile (not sure about web)

Application

Geolocation.currentLocation() //for getting current position 
Geolocation.latLng() //returns object with lat and lng keys 



Are there other points or differences to be aware of Would love to hear from people who have implemented either or both and have things to say/ advice.

Upvotes: 1

Views: 444

Answers (1)

3pic
3pic

Reputation: 1219

Cordova Geolocation is very easy to use. Just use it.

Im trying to save a user's location when an action is done, so it wont be refreshed constantly. Also looking to do simple calculations with the stored values like distance, speed etc.

Cordova doesnt consume a lot when callbacking very often onSuccess. I used to return immediatly, if conditions were not satisfied (less than 10 seconds, less than 50meter, etc.).

Cordova calls onSuccess as soon as geoposition has changed. Cordova is just plugged to the device geolocation layer and Cordova listens to.

**If you really want to toggle geolocation-detection, start & stop Cordova geolocation with a watchID. ** (I find it useless. But can be useful when your app goes background)

/*start*/
var watchId = navigator.geolocation.watchPosition(geolocationSuccess,
                                                      [geolocationError],
                                                      [geolocationOptions]);

    /*stops*/    
watchId=null;

http://cordova.apache.org/docs/fr/3.1.0/cordova_geolocation_geolocation.md.html

Upvotes: 1

Related Questions