我下面這個tuorial - https://developers.google.com/maps/documentation/javascript/examples/geocoding-simple谷歌的地理編碼,而不是通過輸入
我已經把代碼<?php echo the_field('post_code'); ?>
,但我想它地理編碼的負載,而不是通過輸入並提交。我怎樣才能做到這一點?
這是我有:
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(52.375599, -3.471680);
var mapOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}
function codeAddress() {
var address = '<?php echo the_field('post_code'); ?>';
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<div id="map-canvas" style="float:left;height:250px; width:625px;margin-top:25px;"></div>
嗨,羅布我沒有得到你。你想要沒有提供輸入地址或提交按鈕的地理編碼?和'<?php回顯the_field('post_code'); ?>「這有什麼問題? –
@LakshmanaKumar是的,我想要加載地理編碼。在教程中,您必須提供一個地址並點擊提交。我通過'<?php echo the_field('post_code')設置地址; '',所以我想讓它立即對其進行地理編碼並放置標記。 – Rob
地理編碼和地圖初始化後調用'codeAddress'。 –