Javascript 利用谷歌地图感知地理位置
我正在使用google api创建一个功能来感知用户的地理位置,但是我遇到了一个问题,尽管代码似乎没有问题,但输出没有显示出来,即我没有得到任何位置信息。这是我的密码Javascript 利用谷歌地图感知地理位置,javascript,google-api,Javascript,Google Api,我正在使用google api创建一个功能来感知用户的地理位置,但是我遇到了一个问题,尽管代码似乎没有问题,但输出没有显示出来,即我没有得到任何位置信息。这是我的密码 <!DOCTYPE html> <HTML> <HEAD> <TITLE>Geolocation</TITLE> </HEAD> <BODY> <A href = "#" id = "get_location">Get
<!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>
地理定位
变量getter=函数(pos){
var user_latitude=pos.coords.latitude;
var user_longitude=pos.coords.longitude;
var user_坐标=user_纬度+','+user_经度;
document.getElementById('google_map').setAttribute('src','https://maps.google.co.in/?q=“+user_坐标+”&z=60&output=embed”);
}
document.getElementById('get_location')。onclick=function(){
navigator.geolocation.getCurrentPosition(getter);
返回false;
}
看起来您刚刚拼错了纬度
pos.coords.lattitude ;
它应该只有1吨。如果你改变了这一点,你的上述代码将正常工作 看起来你刚刚拼错了纬度
pos.coords.lattitude ;
它应该只有1吨。如果你改变了这一点,你的上述代码将正常工作