您需要Geocode您的地址,然后使用results[idx].geometry.location
设置标记。 (谷歌地图的地理编码页面有an example让你开始。)加入
谷歌代码在这里情况下,它都没有改变/不复存在。
var geocoder, map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
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);
}
});
}
<body onload="initialize()">
<div id="map_canvas" style="width: 320px; height: 480px;"></div>
<div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Encode" onclick="codeAddress()">
</div>
</body>
地理数字文档已经移动(这里)(https://developers.google.com/maps/documentation/javascript/geocoding)和示例[存在](https://developers.google.com/maps/documentation/javascript/geocoding#GeocodingStatusCodes) – 2013-02-06 13:21:33
@ChristianLescuyer - 更新 - 感谢您的帮助! – 2013-02-06 14:11:25