百度地图api定位不准解决

使用getpoint时有时会无法定位,没返回point.

这时转用locationSearch即可,再无法定位,

centerandzoom(city)吧.

 

 


function initializeMap() {
    var map = new BMap.Map('mapDiv');
    //向地图中添加缩略图控件
    map.addControl(new BMap.NavigationControl({type:BMAP_NAVIGATION_CONTROL_ZOOM}));
    map.disableDoubleClickZoom();//禁用双击放大
    // 将地址解析结果显示在地图上,并调整地图视野  
    var ge = new BMap.Geocoder();
    var showTip = function (point) {
        map.centerAndZoom(point, 16);
        var marker = new BMap.Marker(point);
        map.addOverlay(marker);
        var tip = mapInfo['address'] + (mapInfo['logo'] ? '
' : '');
        var infoWindow = new BMap.InfoWindow(tip, {   
            width : 250,     // 信息窗口宽度   
            height: 100,     // 信息窗口高度   
            title : "机构详细地址"  // 信息窗口标题   
        });
        marker.addEventListener("click", function(){          
            this.openInfoWindow(infoWindow);
        });   
        marker.openInfoWindow(infoWindow);      // 打开信息窗口  
    };
    var re = ge.getPoint(mapInfo['address'], function(point){
        if (point) {
            return showTip(point);
        }
        
        new BMap.LocalSearch(mapInfo['city'], {onSearchComplete:function(data){
            if (point = data.getPoi(0)){//取第1个查询结果
                showTip(point.point);
            } else {
                map.centerAndZoom(data.city);
                //_.showMaskDiv({htm:'在地图上解析地址时失败.'});
            }
        }}).search(mapInfo['address'], {forceLocal:1} );
    }, mapInfo['city']);
}

你可能感兴趣的:(js)