Javascript 谷歌地图Api v3-地图打印加载位置错误
我需要帮助我的谷歌地图api在我的网站。我在我的网站中加入了地图,然后自动绘制我的位置或定位我,但问题是它给了我错误的位置,但有些位置是正确的 这是我的网站:Javascript 谷歌地图Api v3-地图打印加载位置错误,javascript,php,google-maps-api-3,geocoding,Javascript,Php,Google Maps Api 3,Geocoding,我需要帮助我的谷歌地图api在我的网站。我在我的网站中加入了地图,然后自动绘制我的位置或定位我,但问题是它给了我错误的位置,但有些位置是正确的 这是我的网站:http://webserver.site88.net/beta-test 这是mycode: <script type="text/javascript"> function writeAddressName(latLng) { var geocoder = new google.maps.Geocoder();
http://webserver.site88.net/beta-test
这是mycode:
<script type="text/javascript">
function writeAddressName(latLng) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
"location": latLng
},
function(results, status) {
if (status == google.maps.GeocoderStatus.OK)
document.getElementById("address").value = results[0].formatted_address;
else
document.getElementById("error").innerHTML += "Unable to retrieve your address" + "<br />";
});
}
function geolocationSuccess(position) {
var userLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
document.getElementById("inLat").value = position.coords.latitude;
document.getElementById("inLong").value = position.coords.longitude;
// Write the formatted address
writeAddressName(userLatLng);
var myOptions = {
zoom : 16,
center : userLatLng,
mapTypeId : google.maps.MapTypeId.ROADMAP,
location_type: google.maps.GeocoderLocationType.ROOFTOP
};
// Draw the map
var mapObject = new google.maps.Map(document.getElementById("map"), myOptions);
// Place the marker
var marker = new google.maps.Marker({
map: mapObject,
position: userLatLng
});
var infowindow = new google.maps.InfoWindow({
content: '<div>'+'<b>'+'You are here '+'</b>'+'</div>'
});
infowindow.open(mapObject,marker);
google.maps.event.addDomListener(window, 'load', geolocateUser);
}
function geolocationError(positionError) {
document.getElementById("error").innerHTML += "Error: " + positionError.message + "<br />";
}
function geolocateUser() {
// If the browser supports the Geolocation API
if (navigator.geolocation)
{
var positionOptions = {
enableHighAccuracy: true,
timeout: 10 * 1000 // 10 seconds
};
navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError, positionOptions);
}
else
document.getElementById("error").innerHTML += "Your browser doesn't support the Geolocation API";
}
</script>
函数writedDressName(latLng){
var geocoder=new google.maps.geocoder();
地理编码({
“位置”:latLng
},
功能(结果、状态){
if(status==google.maps.GeocoderStatus.OK)
document.getElementById(“地址”).value=results[0]。格式化的\u地址;
其他的
document.getElementById(“错误”).innerHTML+=“无法检索您的地址”+”
”;
});
}
功能地理定位成功(职位){
var userLatLng=new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
document.getElementById(“inLat”).value=position.coords.latitude;
document.getElementById(“inLong”).value=position.coords.longitude;
//写格式化的地址
writeAddressName(userLatLng);
变量myOptions={
缩放:16,
中心:userLatLng,
mapTypeId:google.maps.mapTypeId.ROADMAP,
位置类型:google.maps.geocoderllocationtype.roottop
};
//画地图
var mapObject=new google.maps.Map(document.getElementById(“Map”),myOptions);
//放置标记
var marker=new google.maps.marker({
map:mapObject,
职位:userLatLng
});
var infowindow=new google.maps.infowindow({
内容:'+'+'您在这里'+'+''
});
打开(mapObject、marker);
google.maps.event.addDomListener(窗口'load',geolocateUser);
}
函数地理位置错误(位置错误){
document.getElementById(“error”).innerHTML+=“error:”+positionError.message+“
”;
}
函数geolocateUser(){
//如果浏览器支持地理定位API
if(导航器.地理位置)
{
变量位置选项={
EnableHighAccurance:正确,
超时:10*1000//10秒
};
navigator.geolocation.getCurrentPosition(geolocationSuccess、geolocationError、positionOptions);
}
其他的
document.getElementById(“错误”).innerHTML+=“您的浏览器不支持地理位置API”;
}
错误的位置是什么?哪一个是正确的?我们请一些人尝试我们的网站,他们来自不同的地方,他们中的大多数人大约有16个小时的车程,而地图给出了错误的位置。所有用户的当前位置都在菲律宾。当浏览器返回错误位置时,他无法更准确地定位用户(通常只有当GPS设备或WI-FI可用时,才会返回正确位置,否则该过程将基于IP,这可能不会导致准确位置)非常感谢你,莫勒博士!我以为我的密码有问题。