我正在构建一个地图,根据每个商家信息的页面地址填充其位置。我没有反向地理编码器,但想知道是否有办法只添加地址而不是?如果不是我怎么能扭转地理编码我的地址?我真的不了解谷歌上的API页面,而不是这种东西。
继承我的编码:
<script
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyBEbIFpr3iySjmSuJz4mwEomIaXnsA8OdQ&sensor=false">
</script>
<script>
function initialize()
{
var mapProp = {
center: new google.maps.LatLng(51.508742,-0.120850),
zoom:7,
disableDefaultUI:true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("googleMap"),mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<div id="googleMap" style="width:100%;height:100px;"></div>
答案 0 :(得分:1)
您必须使用地理编码器获取某个地点的纬度和经度。
你可以这样做:
var geocoder;
var map;
function initialize()
{
geocoder = new google.maps.Geocoder();
var mapProp = {
center: new google.maps.LatLng(51.508742,-0.120850),
zoom:7,
disableDefaultUI:true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
geocoder.geocode({ 'address': 'London' }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
// To add a marker:
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);
所有信息均可在https://developers.google.com/maps/documentation/javascript/geocoding
上找到