gpt4 book ai didi

javascript - 地理定位太慢了!我做错了什么?

转载 作者:行者123 更新时间:2023-12-03 01:42:59 25 4
gpt4 key购买 nike

这是我在测试页面中使用的简单代码:但需要很长时间才能找到地址......怎么会?我做错了什么吗?

<script src="http://maps.google.com/maps?hl=it&amp;file=api&amp;v=2&amp;sensor=true&amp;key=*xxxxxx*" type="text/javascript"></script>
<script type="text/javascript">
var map;
var geocoder;

function addAddressToMap(response)
{
if (!response || response.Status.code != 200)
{
alert("Sorry, we were unable to geocode that address");
}
else
{
place = response.Placemark[0];
point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);

document.getElementById('address').innerHTML = place.address;
}
}


function searchGeolocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function(position)
{
geocoder = new GClientGeocoder();
document.getElementById('latitude').innerHTML = position.coords.latitude;
document.getElementById('longitude').innerHTML = position.coords.longitude;
coordinates = position.coords.latitude+","+position.coords.longitude;
geocoder.getLocations(coordinates, addAddressToMap);

});
}else
{
document.getElementById('latitude').innerHTML = "Unknown";
document.getElementById('longitude').innerHTML = "Unknown";
document.getElementById('address').innerHTML = "Unknown";
alert("I'm sorry, but geolocation services are not supported by your browser.");
}
}



</script>


<br/>
latitude = <div id="latitude">loading...</div>
<br/>
longitude = <div id="longitude">loading...</div>
<br/>
address = <div id="address">loading...</div>
<br/>


<script type="text/javascript">

searchGeolocation();

</script>

最佳答案

嗯 - 它实际上是在进行地理定位!

为了加快速度,请考虑提供额外的参数来利用缓存的结果和超时。

关于javascript - 地理定位太慢了!我做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3752383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com