当前位置: 动力学知识库 > 问答 > 编程问答 >

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: