I’m trying to load latitude and longitude value using this code but I receive back this error:
Uncaught ReferenceError: position is not defined
(anonymous function)
here is the code I used in the head of html:
<script src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
$(document).ready(function(){
get_location();
});
function get_location()
{
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function(position){
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
});
}
}
console.log(position.coords);
</script>
I forgot something ?
must be
You can add callback errorHandle to get errorCode
More info http://dev.w3.org/geo/api/spec-source.html#geolocation