从当前缩放谷歌地图获取边界经度和纬度 [英] get boundaries longitude and latitude from current zoom google maps

查看:734
本文介绍了从当前缩放谷歌地图获取边界经度和纬度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道当前区域
的四个角的长和宽,就像这张图中的一样


我试过这个,但没有运气:

  map.getBounds(); 

任何帮助?

解决方案

你在那里的一半。您只需获取地图边界,然后提取(并正确使用)拐角的坐标。

  var bounds = map.getBounds(); 
var ne = bounds.getNorthEast(); //东北角的LatLng
var sw = bounds.getSouthWest(); //西南角的经纬度

您从西南角和西南角以上两项:

  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){
//在这里更新坐标
});


i need to know long and lat of my four corners of current area as in this image

i have tried this but with no luck :

map.getBounds();

any help ?

解决方案

You are half way there. All you need to do is to get the map bounds and then extract (and properly use) the coordinates of the corners.

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

You get north-west and south-east corners from the two above:

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

Just keep in mind that the map has to be already initialized, otherwise the map bounds are null or undefined.

If you want to be updated about every change of the viewport, use idle event listener:

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

这篇关于从当前缩放谷歌地图获取边界经度和纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆