I am using the Cordova geolocation plugin and I’m setting up a location watch in my app.js… I would like to be able to emit an event with this data that I can pick up on certain pages. So far I have the following which does generate an event but I don’t know how to set different listeners for different pages.
var watchID = navigator.geolocation.watchPosition(
function (position) {
app.emit('locationChange', position.coords.latitude, position.coords.longitude );
},
function(error) {
app.emit('locationError', error.code, error.message );
},
);
Is there a better way to emit to a specific component scope which I can then tap into using the on
listener?
return {
on: {
locationChange: function( lat, lng ) {
// Do stuff here
}
}
}