当我加载页面时
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"> </script>
<script src="https://maps.googleapis.com/maps/api/js?key=hgter...&libraries=places" type="text/javascript"> </script>
<script>
var map = new google.maps.Map(document.getElementById('map-canvas'), {
center: {
lat: 12.971599,
lng: 77.594563
},
zoom: 15
});
var marker = new google.maps.Marker({
position: {
lat: 12.971599,
lng: 77.594563
},
map: map,
draggable: true
});
var searchBox = new
google.maps.places.SearchBox(document.getElementById('searchmap'));
google.maps.event.addListener(searchBox, 'places_changed', function() {
var places = searchBox.getPlaces();
var bounds = new google.maps.LatLngBounds();
var i, place;
for (i = 0; place = places[i]; i++) {
bounds.extend(place.geometry.location);
marker.setPosition(place.geometry.location);
}
map.fitBounds(bounds);
map.setZoom(15);
});
google.maps.event.addListener(marker, 'position_changed', function() {
var lat = marker.getPosition().lat();
var lng = marker.getPosition().lng();
$('#lat').val(lat);
$('#lng').val(lng);
});
</script>
当你移动你的标记时,你改变了你的纬度和液化天然气输入值,没关系。
但是你所谓的"位置"(我猜你的 #searchmap 输入(与它没有联系。如果要替换它,则需要 反向地理编码 : https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse?hl=fr
您给出 lat+lng,反向地理编码答案,并在这个地方找到位置。