Google maps api 3 上失败的地理编码地图未设置为提供的坐标
我正在使用以下代码初始化Google地图:Google maps api 3 上失败的地理编码地图未设置为提供的坐标,google-maps-api-3,Google Maps Api 3,我正在使用以下代码初始化Google地图: function googleMapinitialize(fenceAddIn){ var fenceAdd=new google.maps.LatLng(37.2146,121.5545); var mapProp = { center:fenceAdd, zoom:30, mapTypeId:google.maps.MapTypeId.TERRAIN }; var map = new google.
function googleMapinitialize(fenceAddIn){
var fenceAdd=new google.maps.LatLng(37.2146,121.5545);
var mapProp = {
center:fenceAdd,
zoom:30,
mapTypeId:google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById("fenceMap"),mapProp);
var geocoder = new google.maps.Geocoder();
var location = fenceAddIn; //"2001 Gateway PI, San Jose, CA";
if(!geocoder) {
geocoder = new google.maps.Geocoder();
}
var geocoderRequest = {
address: location
}
var myCity = null;
var marker = null;
var infowindow = null;
geocoder.geocode(geocoderRequest, function(results, status) {
if (status =="" || status == google.maps.GeocoderStatus.ZERO_RESULTS){
alert("'" + location + "' not found!!!");
map.setCenter(fenceAdd);
} else if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
fenceAdd = new google.maps.LatLng(results[0].geometry.location.hb,results[0].geometry.location.ib);
if (!marker) {
marker = new google.maps.Marker({
map: map,
raiseOnDrag:false,
draggable:true
});
marker.setPosition(results[0].geometry.location);
google.maps.event.addListener(marker,'click',function(){
if (!infowindow) {
infowindow = new google.maps.InfoWindow({
disableAutoPan:true,
maxWidth:100
});
}
var content = '<strong>' + results[0].formatted_address + '</strong>';
infowindow.setContent(content);
infowindow.setPosition(results[0].geometry.location);
infowindow.open(map, marker);
});
}
}
myCity = new google.maps.Circle({
center:fenceAdd,
radius:125,
strokeColor:"#0000ff",
strokeOpacity:0.1,
strokeWeight:0.1,
fillColor:"#0000ff",
fillOpacity:0.20,
map:map
});
google.maps.event.addListener(map, 'click', function(){
infowindow.close();
});
google.maps.event.addListener(map, 'dblclick', function(){
window.open("<%=request.getContextPath() %>/jsp/googleMapPopup.jsp?fenceAddress="+$('#haddr').val(),'ADDRESSMAP','height=400,width=600');
});
});
}
函数googleMapinitialize(fenceAddIn){
var fenceAdd=new google.maps.LatLng(37.2146121.5545);
var mapProp={
中心:fenceAdd,
缩放:30,
mapTypeId:google.maps.mapTypeId.TERRAIN
};
var map=new google.maps.map(document.getElementById(“fenceMap”),mapProp);
var geocoder=new google.maps.geocoder();
var location=fenceAddIn;/“2001年加利福尼亚州圣何塞网关PI”;
if(!地理编码器){
geocoder=新的google.maps.geocoder();
}
var geocoderRequest={
地址:地址
}
var myCity=null;
var-marker=null;
var infowindow=null;
geocoder.geocode(geocoderRequest,函数(结果,状态){
if(status==“”| | status==google.maps.GeocoderStatus.ZERO_结果){
警报(“'”+位置+“'未找到!!!”);
地图设置中心(fenceAdd);
}else if(status==google.maps.GeocoderStatus.OK){
map.setCenter(结果[0].geometry.location);
fenceAdd=new google.maps.LatLng(结果[0].geometry.location.hb,结果[0].geometry.location.ib);
如果(!标记){
marker=新的google.maps.marker({
地图:地图,
理由:错,
德拉格布尔:是的
});
marker.setPosition(结果[0].geometry.location);
google.maps.event.addListener(标记,'click',函数(){
如果(!infowindow){
infowindow=新建google.maps.infowindow({
是的,
最大宽度:100
});
}
var content=''+结果[0]。格式化的地址+'';
infowindow.setContent(content);
infowindow.setPosition(结果[0].geometry.location);
信息窗口。打开(地图、标记);
});
}
}
myCity=新建google.maps.Circle({
中心:fenceAdd,
半径:125,
strokeColor:#0000ff“,
笔划不透明度:0.1,
冲程重量:0.1,
fillColor:#0000ff“,
不透明度:0.20,
地图:地图
});
google.maps.event.addListener(映射,'click',函数(){
infowindow.close();
});
google.maps.event.addListener(映射'dblclick',函数(){
window.open(“/jsp/googleMapPopup.jsp?fenceAddress=“+$('haddr').val(),'ADDRESSMAP','height=400,width=600');
});
});
}
我正在发送一个地址,地址用地理编码,位置用图钉在地图上标出。但如果地理编码失败,地图将以中国为中心。所以为了克服这个问题,我将地图中心重置为原来的lat-long,并在上面画圆。当我调试代码时,我看到坐标设置正确,但地图仍然显示中国地图
有人能告诉我在这种情况下如何重置地图位置吗 您的fenceAdd坐标默认为China: 中国山东烟台牟平206省道(37.21401121.5955285) 如果不想让地图居中,请更改这些坐标