我的地理位置功能不起作用怎么办? [英] My geolocation function is not working what to do?

查看:110
本文介绍了我的地理位置功能不起作用怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,它首先在某个位置显示地图,然后在点击尝试它按钮后,我想显示用户的当前位置。这是代码

i have this following code which shows a map initially at some position and then after clicking the button "try it" i want to show the user's current location. here is the code

<!DOCTYPE html>
<html>
<head>
<script
src="http://maps.googleapis.com/maps/a…

<script>
function initialize()
{
var mapProp = {
center:new google.maps.LatLng(51.508742,-0.120850),
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById(…
}

google.maps.event.addDomListener(windo… 'load', initialize);
</script>
</head>

<body>
<div id="googleMap" style="width:500px;height:380px;"></div>
<p id="demo">Click the button to get your position:</p>
<button  önclick="getLocation()">Try It</button>

<script>
var x=document.getElementById("demo");
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition…
}
else{x.innerHTML="Geolocation is not supported by this browser.";}
}
function showPosition(position)
{
lat=position.coords.latitude;
lon=position.coords.longitude;
latlon=new google.maps.LatLng(lat, lon)
mapholder=document.getElementById(google…
mapholder.style.height='500px';
mapholder.style.width='500px';

var myOptions={
center:latlon,zoom:7,
mapTypeId:google.maps.MapTypeId.ROADMAP,
mapTypeControl:false,
navigationControlOptions:{style:google.m…
};
var map=new google.maps.Map(document.getElementById(…
var marker=new google.maps.Marker({position:latlon,map:… are here!"});
}

function showError(error)
{
switch(error.code) 
{
case error.PERMISSION_DENIED:
x.innerHTML="User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML="Location information is unavailable."
break;
case error.TIMEOUT:
x.innerHTML="The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML="An unknown error occurred."
break;
}
}
</script>
</body>
</html>





地图最初显示但点击试试按钮后没有任何事情发生。该怎么办?



the map is showing initially but after clicking the try it button nothing is happening. what to do?

推荐答案

我会尝试调试Javascript以查看它的功能
I would try debugging the Javascript to see what it does


这篇关于我的地理位置功能不起作用怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆