我一直在尋找Google maps dev網站上的地理編碼示例。我發現這個例子,並希望作爲一個實驗硬代碼郵政編碼,而不是使用輸入框來獲取地址(總體目標是讓xml在這裏放置郵政地址)。這只是一個硬編碼'地址'標籤內的郵政地址的情況嗎?我確實嘗試過但不喜歡。希望這是有道理的?Hardcode是用於地理編碼的郵政地址
<script>
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
zoom: 8,
center: latlng
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}
function codeAddress() {
var address = document.getElementById('address').value;
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>
</head>
<body>
<div id="panel">
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Geocode" onclick="codeAddress()">
</div>
<div id="map-canvas"></div>
</body>
https://developers.google.com/maps/documentation/javascript/examples/geocoding-simple
你嘗試VAR地址= 「NY」? –