Mayank Pathak Mayank Pathak - 1 month ago 12
Javascript Question

sensing geolocation using google maps

I am creating a functionality to sense the users geolocation using google api but i am having a problem that although the code seems to be alright the output is not showing i.e i am getting nothing as my location. Here is my code

<!DOCTYPE html>
<HTML>
<HEAD>
<TITLE>Geolocation</TITLE>
</HEAD>
<BODY>
<A href = "#" id = "get_location">Get Location</A>
<DIV id = "map">
<IFRAME id = "google_map" width = "400" height = "350" frameborder = "0" scrolling = "no" marginheight = "0" marginwidth = "0" src = "https://maps.google.co.in?output=embed"></IFRAME>
</DIV>
<SCRIPT type = "text/javascript">
var getter = function(pos) {
var user_lattitude = pos.coords.lattitude;
var user_longitude = pos.coords.longitude;
var user_coordinates = user_lattitude + ',' + user_longitude;
document.getElementById('google_map').setAttribute('src' , 'https://maps.google.co.in/?q=' + user_coordinates + '&z=60&output=embed');
}
document.getElementById('get_location').onclick = function() {
navigator.geolocation.getCurrentPosition(getter);
return false;
}
</SCRIPT>
</BODY>
</HTML>

Answer Source

It looks like you've just spelt latitude wrong.

pos.coords.lattitude ;

It should only have 1 t. If you change that your above code will work.