This question already has an answer here:
need custom function, which return current coordintes, or if navigator not works return default coordinates.
Here is my code:
function GetCoorinates() {
var lon, lat;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (location) {
console.log(location.coords.latitude);
console.log(location.coords.longitude);
lat = location.coords.latitude;
lon = location.coords.longitude;
return [lon, lat]
});
} else {
return [40.13, 19.68];
}
};
Function always return undefined, but when I try print actual value of location.coords.latitude, it looks correct. Any ideas?
Aucun commentaire:
Enregistrer un commentaire