0
我正在努力實現地圖相同像uber.it包含皮卡位置標記,當我改變標記位置時,它顯示我的fromaddress文本框上的當前地址......但是當我在fromaddress文本框輸入一些地址我想要更改地圖上的標記位置。超級喜歡拖曳的地圖
請人幫我做這個
<script type="text/javascript">
var map;
var marker;
var myLatlng = new google.maps.LatLng('<?php echo $static_lat; ?>','<?php echo $static_lng; ?>');
var geocoder = new google.maps.Geocoder();
var infowindow = new google.maps.InfoWindow();
function initialize(){
var mapOptions = {
zoom: 13,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), mapOptions);
marker = new google.maps.Marker({
map: map,
position: myLatlng,
draggable: true
});
geocoder.geocode({'latLng': myLatlng }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
$('#fromlat,#fromlong').show();
$('#fromaddress').val(results[0].formatted_address);
$('#fromlat').val(marker.getPosition().lat());
$('#fromlong').val(marker.getPosition().lng());
infowindow.setContent(results[0].formatted_address);
infowindow.open(map, marker);
}
}
});
google.maps.event.addListener(marker, 'dragend', function() {
geocoder.geocode({'latLng': marker.getPosition()}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
$('#fromaddress').val(results[0].formatted_address);
$('#fromlat').val(marker.getPosition().lat());
$('#fromlong').val(marker.getPosition().lng());
infowindow.setContent(results[0].formatted_address);
infowindow.open(map, marker);
}
}
});
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
精彩,非常感謝你的代碼。爲我節省很多時間。 –