Google-地图地理编码服务
Google-maps geocoding service
您好,我在地理编码服务中使用 google 文档。
脚本应该显示卡萨布兰卡的位置,但它仍然显示澳大利亚的默认位置
问题是geocoder.geocode(...)没有执行
function initMap() {
var geocoder = new google.maps.Geocoder();
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
scrollwheel: false,
zoom: 8,
});
codeAddress(geocoder,map);
}
function codeAddress(geocoder, map)
{
var addr = "Casablanca";
geocoder.geocode( {'addr':addr}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
map.setCenter(results[0].geometry.addr);//center the map over the result
//place a marker at the location
var marker = new google.maps.Marker(
{
map: map,
position: results[0].geometry.addr
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
PS:
我正在使用 GooglMapper https://github.com/bradcornford/Googlmapper
感谢任何帮助。
geocoder.geocode( {'addr':addr}, function(results, status)
应该是:
geocoder.geocode( {'address':addr}, function(results, status)
GeocoderRequest 对象文字包含以下字段:
{
address: string,
location: LatLng,
placeId: string,
bounds: LatLngBounds,
componentRestrictions: GeocoderComponentRestrictions,
region: string
}
回答我的问题
map.setCenter(results[0].geometry.addr);
应该是
map.setCenter(results[0].geometry.location);
和
position: results[0].geometry.addr
应该
position: results[0].geometry.location
您好,我在地理编码服务中使用 google 文档。
脚本应该显示卡萨布兰卡的位置,但它仍然显示澳大利亚的默认位置
问题是geocoder.geocode(...)没有执行
function initMap() {
var geocoder = new google.maps.Geocoder();
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
scrollwheel: false,
zoom: 8,
});
codeAddress(geocoder,map);
}
function codeAddress(geocoder, map)
{
var addr = "Casablanca";
geocoder.geocode( {'addr':addr}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
map.setCenter(results[0].geometry.addr);//center the map over the result
//place a marker at the location
var marker = new google.maps.Marker(
{
map: map,
position: results[0].geometry.addr
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
PS: 我正在使用 GooglMapper https://github.com/bradcornford/Googlmapper
感谢任何帮助。
geocoder.geocode( {'addr':addr}, function(results, status)
应该是:
geocoder.geocode( {'address':addr}, function(results, status)
GeocoderRequest 对象文字包含以下字段:
{
address: string,
location: LatLng,
placeId: string,
bounds: LatLngBounds,
componentRestrictions: GeocoderComponentRestrictions,
region: string
}
回答我的问题
map.setCenter(results[0].geometry.addr);
应该是
map.setCenter(results[0].geometry.location);
和
position: results[0].geometry.addr
应该
position: results[0].geometry.location