【问题标题】:get boundaries longitude and latitude from current zoom google maps从当前缩放谷歌地图获取边界经度和纬度
【发布时间】:2011-10-18 03:48:48
【问题描述】:

我需要知道当前区域四个角的经纬度 就像这张图

我试过了,但没有运气:

map.getBounds();

有什么帮助吗?

【问题讨论】:

    标签: google-maps-api-3 maps


    【解决方案1】:

    你已经成功了一半。您需要做的就是获取地图边界,然后提取(并正确使用)角落的坐标。

    var bounds = map.getBounds();
    var ne = bounds.getNorthEast(); // LatLng of the north-east corner
    var sw = bounds.getSouthWest(); // LatLng of the south-west corder
    

    您可以从上面的两个角落获得西北角和东南角:

    var nw = new google.maps.LatLng(ne.lat(), sw.lng());
    var se = new google.maps.LatLng(sw.lat(), ne.lng());
    

    请记住,地图必须已经初始化,否则地图边界为空或未定义。

    如果您想了解视口的每次更改,请使用idle 事件监听器:

    google.maps.event.addListener(map, 'idle', function(ev){
        // update the coordinates here
    });
    

    【讨论】:

    • 感谢您让我不必用我的大脑来寻找 nw 和 se 角落。
    • @Tomic 到目前为止,我知道 iOS SDK 的 googlemap api 现已付费,请问您能给我其他解决方案吗?
    【解决方案2】:

    在Android中,你可以通过这种方式找到角落LatLng(东北,西南), 在地图中,每次相机监听(意味着手势检测)时,它们都会被调用,

    private var mapView: GoogleMap? = null
    

    ............

        mapView?.setOnCameraMoveStartedListener { reasonCode ->
            if (reasonCode == GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE) {
                val screenView: LatLngBounds =  mapView.getProjection().getVisibleRegion().latLngBounds
                var northeast=screenView.northeast
                var southwest=screenView.southwest
                var center=screenView.center
                
                
                Log.v("northeast LatLng","-:"+northeast)// LatLng of the north-east Screen
                Log.v("southwest LatLng","-:"+southwest)// LatLng of the south-west Screen
                Log.v("center LatLng","-:"+center)// LatLng of the center Screen
            }
        }
    

    【讨论】:

      【解决方案3】:
      **this is mapbox zoom example**
       map.on('zoom', (el) => {
              map.getBounds();
          });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-06-20
        • 2021-08-22
        • 2012-09-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多