Juan Juan - 7 months ago 75
Javascript Question

Geolocation with javascript

I want to obtain the latitude and the longitude from the navigator and then show them. My code is not working, it is not showing the alert:

$(document).ready(function() {

var long;
var lat;

if(navigator.geolocation) {

navigator.geolocation.getCurrentPosition(function(position) {

lat = position.coords.latitude;
long = position.coords.longitude;

alert(long + " " + lat);


I think your code is fine. The issue will most likely be that you are trying to use the Geolocation API on an insecure connection. Make sure you are viewing your page on https.