This question already has an answer here:
Why do i always get undefined on object location1 lat and lng properties? I have been trying this now for like 2 hours, always undefined no matter what i do..
<script>
function getLocation()
{
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
}
}
function locations(lat,lng)
{
this.lat = lat;
this.lng = lng;
}
function showPosition(position)
{
window.lat = position.coords.latitude;
window.lng = position.coords.longitude;
}
getLocation();
var location1 = new locations(window.lat,window.lng);
</script>
Aucun commentaire:
Enregistrer un commentaire