Google maps 基于城市名称谷歌地图获取坐标
我正在尝试用谷歌地图创建基于城市的坐标,这里是我现在的例子,我总是得到错误Google maps 基于城市名称谷歌地图获取坐标,google-maps,geocode,Google Maps,Geocode,我正在尝试用谷歌地图创建基于城市的坐标,这里是我现在的例子,我总是得到错误 var address = 'Zurich, Ch'; var geocoder = new google.maps.Geocoder(); geocoder.geocode({ 'address': address }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var Lat = resul
var address = 'Zurich, Ch';
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
'address': address
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var Lat = results[0].geometry.location.lat();
var Lng = results[0].geometry.location.lng();
} else {
alert("Something got wrong " + status);
}
});
var myOptions = {
zoom: 11,
center: new google.maps.LatLng(Lat, Lng),
};
地理编码器是异步的。当返回的数据可用时,需要在回调函数中使用返回的数据 相关问题: 代码片段:
函数初始化(){
var地址='苏黎世,瑞士';
var geocoder=new google.maps.geocoder();
地理编码({
“地址”:地址
},功能(结果、状态){
if(status==google.maps.GeocoderStatus.OK){
var Lat=results[0]。geometry.location.Lat();
var Lng=results[0]。geometry.location.Lng();
变量myOptions={
缩放:11,
中心:新google.maps.LatLng(Lat,Lng)
};
var map=new google.maps.map(
getElementById(“地图画布”),myOptions;
}否则{
警惕(“出错”+状态);
}
});
}
google.maps.event.addDomListener(窗口“加载”,初始化)代码>
html,
身体,
#地图画布{
身高:100%;
宽度:100%;
边际:0px;
填充:0px
}
您会遇到什么错误?