问题描述:

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.

相关阅读:
Top