I made a simple GPS tracking app that draws a line to the current location and moves a marker each time the location changes.
BTek-GPS-Trakker.jpg
Code:
cordova.exec(
function SuccessHandler (result) {
// Center the map
me.getComponent('map').setMapCenter({ atitude: result.latitude, longitude: result.longitude});
if (MyApp.app.LastLatitude !== null && MyApp.app.LastLatitude !== '')
{
// Add a line to the map
var flightPlanCoordinates = [
new google.maps.LatLng(MyApp.app.LastLatitude, MyApp.app.LastLongitude),
new google.maps.LatLng(result.latitude, result.longitude)
];
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: "#4682b4",
strokeOpacity: 0.8,
strokeWeight: 2
});
flightPath.setMap(me.getComponent('map').getMap());
// Remove the old marker
MyApp.app.Marker.setMap(null);
}
// Add a new marker
var position = new google.maps.LatLng (result.latitude, result.longitude);
MyApp.app.Marker = new google.maps.Marker({
position: position,
title: result.latitude + ', ' + result.longitude,
icon: 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png',
map: me.getComponent('map').getMap()
});
MyApp.app.Marker.setMap(me.getComponent('map').getMap());
MyApp.app.LastLatitude = result.latitude;
MyApp.app.LastLongitude = result.longitude;
},
function ErrorHandler (error) {
alert("Native call failed: " + error);
},
'BTekGPSPlugin', '', []);
}, this);
The source is on GitHub and the calls that get the coordinates from native code are detailed here: http://www.btek.com.au/tracking-move...ative-process/. I used a custom GPS class because the coordinates will need to be pre-processed by existing business logic.