1:地圖顯示不全
解決:在初始化時實例化map
</pre><pre name="code" class="javascript">$(function(){
map_info();
});
//剛進入時加載地圖
function map_info(){
//百度地圖API功能
map = new BMap.Map("map");
map.centerAndZoom('西安市',14);
//滾輪設置地圖大小
map.enableScrollWheelZoom(true);
}
2:地圖座標出現在左or右上角,不居中
解決:map.setViewport(); 或 map.panBy(305,165)
//點擊某個地圖模態窗口時加載座標點
function addPoint(x,y){
//清除上一個打開的座標點
map.clearOverlays();
//判斷baidu座標是否爲空
if(x != null && x != '' && y != null && y != ''){
//添加座標點
map.centerAndZoom(new BMap.Point(x,y), 14);
map.setViewport();
var marker = new BMap.Marker(new BMap.Point(x, y));
map.addOverlay(marker);
}else{ //如果爲空則使用IP地址定位
map.centerAndZoom('西安市',14);
var myCity = new BMap.LocalCity();
myCity.get(myFun);
}
}