首页 > 百度地图找到已经标记点位置的经纬度

百度地图找到已经标记点位置的经纬度

百度地图找到已经标记点位置的经纬度,
利用ip去定位所在地方
/*============================

    *添加地图标志,得到定位的经纬度
    **/
    //创建地图Map实例
    var map = new BMap.Map("addMap");
    //中心点设置
    map.centerAndZoom( new BMap.Point(116.331398,39.897445), 11);
    map.enableScrollWheelZoom( true);
    map.enableContinuousZoom();
    //根据IP得到当前城市, 并定位
    var point = new BMap.Point(116.331398,39.897445);
    map.centerAndZoom(point,12);

    function myFun(result){
        var cityName = result.name;
        map.setCenter(cityName);
        console.log("当前定位城市:"+cityName);
        var lngLat = result.center;
        console.log( "target lngLat", lngLat);
         $("#addSubmit").click(function( event, wlngLat) {
                console.log("this listen lngLat", wlngLat);//undefined
                console.log( "This is addSubmit params", params);
                addSubmit( params, wlngLat);
            });
        return lngLat;
    }
    var myCity = new BMap.LocalCity();
    myCity.get(myFun);
    console.log( myCity.get( myFun));

而后 我想得到已经定位了经纬度 用到其他的函数,该怎么处理呢?
或者 该去怎么找到这个 已经定位好了的标记点的经纬度呢?


var map = new BMap.Map("allmap");            // 创建Map实例
      var wlngLat;
    map.centerAndZoom( new BMap.Point(116.331398,39.897445), 11);
    map.enableScrollWheelZoom( true);
    map.enableContinuousZoom();
    var point = new BMap.Point(116.331398,39.897445);
    map.centerAndZoom(point,12);
  function myFun(result){
        var cityName = result.name;
        map.setCenter(cityName);
        console.log("当前定位城市:"+cityName);
        var lngLat = result.center;
        console.log( "target lngLat", lngLat);
        wlngLat = lngLat;
        return lngLat;
    }
    var myCity = new BMap.LocalCity();
    myCity.get(myFun);
    
    //处理这种异步的东西,这里好像没有办法以回调的形式处理,可以循环检查
    
    var inv = setInterval(function(){
        if(wlngLat){
            clearInterval(inv);
            console.log(wlngLat)
        }
            
    },100);
    

 $("#addSubmit").click(function( event) {
    console.log("this listen lngLat", wlngLat);//wlngLat 不用传递。。。。
    console.log( "This is addSubmit params", params);
    addSubmit( params, wlngLat);
});
【热门文章】
【热门文章】