日期:2014-05-18 浏览次数:20581 次
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(); }