- JScript code
function getPOI() { address1 = document.getElementById("address1").value; geocoder.geocode({'address': address1}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { mylatlng=results[0].geometry.location; getAddress();//根据坐标得到详细地址 } }); } function getAddress() { geocoder.geocode({'latLng': mylatlng}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { if (results[1]) { map.setZoom(11); var myOptions= { zoom:11, center:mylatlng, mapTypeId:google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById("myMap"), myOptions); infocontent=results[0].formatted_address; marker = new google.maps.Marker({ position: mylatlng, map: map, draggable:true }); infowindow.setContent(results[1].formatted_address); infowindow.open(map, marker); movemarker(); } } else { alert("Geocoder failed due to: " + status); } }); } //移动图标的事件,需要增加addlistener function movemarker() { google.maps.event.addListener(marker,'dragend',function(event) { newposition();//获取新坐标 }); infowindow.setContent(infocontent); infowindow.open(map,marker); } //处理新坐标,并重新进行反向地址解析 function newposition() { var mylatlng=marker.getPosition(); getAddress(); }
为什么鼠标把显示的图标移动到一个新地方后之后没有显示新地方的信息,反而又回来开始的位置了?
------解决方案--------------------------------------------------------
mylatlng=results[0].geometry.location;
position: mylatlng,
var mylatlng=marker.getPosition();你这有三个mylatlng,你还是区别一下试试。