我的谷歌地图API脚本发生了一些事情 [英] Something happened to my google map api script
问题描述
在完成web部分之后,我一直在做我的项目的移动部分。我正在使用谷歌地图API。我已经编码如下:
I've been doing mobile part of my project after "completing" the web part. I'm using google map api. I have coded following:
function codeAddress() {
var image = 'images/tickmark1.png';
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var markerZad = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
title: "NEW TASK",
icon: image
});
document.getElementById('latitude').value =results[0].geometry.location.nb.toPrecision(9);
document.getElementById('longitude').value=results[0].geometry.location.ob.toPrecision(9);
document.getElementById('adrs').value=document.getElementById('address').value;
document.getElementById('latit').value =results[0].geometry.location.nb.toPrecision(9);
document.getElementById('longit').value=results[0].geometry.location.ob.toPrecision(9);
alert("Ustalono wspolrzedne nowego zadania. Wybierz pracownika \n (PPM usuwa znacznik)");
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
google.maps.event.addListener(markerZad, 'click', function() {
alert("Nowe zadanie: \n"+ address + "\n"+"Wybierz pracownika \n (PPM usuwa znacznik)");
map.setZoom(14);
map.setCenter(this.getPosition());
});
google.maps.event.addListener(markerZad, 'rightclick', function() {
markerZad.setMap(null);
document.getElementById('latitude').value =0;
document.getElementById('longitude').value=0;
document.getElementById('adrs').value=0;
document.getElementById('latit').value =0;
document.getElementById('longit').value=0;
document.getElementById('ajdideva').value="X";
document.getElementById('iddev').value=0;
document.getElementById('baton').disabled=true;
alert("Usunieto znacznik. Wpisz inny adres.");
});
});
}
让我们留下这段代码的级别。我确定这是一个糟糕的。但事情是......它几天前曾经为我工作。现在它不。是的,自那以后我就没有触及它......我想通了,这个问题导致了结果。我得到状态== OK,然后它将标记放在正确的位置,然后......没有任何反应。我的意思是我在html文件中的输入不会改变它们的值并且+监听器不工作。当我改变结果[0]。等简单的字符串,它的工作原理,这就是为什么我认为结果[0]有问题。有什么建议吗?
Let's leave behind the level of this code. I'm sure it's a bad one. But the thing is...it used to work for me like few days ago. Now it doesn't. And yes, I haven't touched it since then... I figured out myself, that the problem causes "results". I get status==OK, then it places a marker in a correct spot, and then...nothing happens. I mean my inputs in html file don't get their values changed and +listeners aren't working. When I changed "results[0]." etc to simple string, it worked, that's why I think that there's a problem with results[0]. Any suggestions please?
推荐答案
不要访问未记录的属性,例如 results [0] .geometry.location.nb
。这些财产的名称可能(而且将会)改变。为了访问这些属性的值,使用记录的方法,例如 lat()
可以访问 LatLng
-instance的范围:
Don't access undocumented properties like e.g. results[0].geometry.location.nb
. The names of these properties may(and will) change. To access the values of these properties use the documented methods, e.g. lat()
to access the latitude of a LatLng
-instance:
document.getElementById('latitude').value
= results[0].geometry.location.lat().toPrecision(9);
这篇关于我的谷歌地图API脚本发生了一些事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!