I'm new to JS and I'm trying to build a web app with PhoneGap that takes GPS coordinates from an Android device and uses them in some JS functions, but I'm having trouble. How should I pass 'lat' and 'lon' to use them in 'coords'
document.addEventListener("deviceready", onDeviceReady, false);
var lat;
var lon;
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
// onSuccess Geolocation
//
function onSuccess(position) {
var lat = position.coords.latitude;
var lon = position.coords.longitude;
}
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
var map;
function initMap() {
var coords = new google.maps.LatLng(lat,lon);
map = new google.maps.Map(document.getElementById('map_canvas'), {
center: coords,
zoom: 15
});
var marker = new google.maps.Marker({
position: coords,
map: map,
title: 'Вие сте тук!'
});
}
onSuccess();
onError();
initMap();