在Google Maps API V3中获取非包裹地图边界 [英] Get non-wrapping map bounds in Google Maps API V3

查看:246
本文介绍了在Google Maps API V3中获取非包裹地图边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您放大Google地图,世界将开始水平重复。使用.getBounds()似乎返回显示的地图图像边缘的经度。但我想获得当前真实世界视图的最小和最大经度。



例如,在这个图像中.getBounds()表示经度在116和37度(宽​​度为-79度!)。我正在寻找的范围是-244到+37。
(甚至-180到+37,因为这是在地图中心周围可以看到的世界极值)。



另一个例子。在这里,我正在寻找-180到+180 ...



您可以在这里尝试一下...
http://jsfiddle.net/spiderplant0/EBNYT/



(道歉,如果之前已经回答 - 我确实发现了一些旧的类似问题但似乎没有一个满意的答案)。

解决方案

今天我遇到了同样的问题,但我想我终于明白了。

在上面的第一个场景中,可以使用map.getBounds()。toSpan()获取经度的宽度.....只要地图没有环绕。



对于地图环绕的第二个场景,我扩展了 google.maps.OverlayView()来获取 google.maps.MapCanvasProjection 对象。从那里你可以调用函数 getWorldWidth()



它会以像素为单位给出世界宽度,然后您可以将其与地图容器的宽度进行比较。如果你的容器比较大,你的地图就会被环绕。



不知道这个函数是否适合这个,但它可以工作。


If you zoom a google map out the world will start to repeat horizontally. Using .getBounds() seems to return the longitude at the edges of the displayed map image. But I would like to get minimum and maximum longitudes for the current view of the real world.

For example in this image .getBounds() says that the longitude ranges between 116 and 37 degrees (giving a width of -79 degrees!). The range I'm looking for is -244 to +37. (or even -180 to +37 as this is the extremes of the world that is viewable around the map centre.)

And another example. Here I'm looking for -180 to +180 ...

You can try it for yourself here... http://jsfiddle.net/spiderplant0/EBNYT/

(Apologies if this has been answered before - I did find some old similar questions but none seemed to have satisfactory answers).

解决方案

I ran into the same issues today, but I think I finally figured it out.

In the first scenario above, you can use map.getBounds().toSpan() to get the width in longitude.....as long as the map did not wrap around.

For the second scenario where the map wraps around, I extended the google.maps.OverlayView() to get the google.maps.MapCanvasProjection object. From there you can call the function getWorldWidth().

It will give you the world width in pixel, then you can compare it with your map container's width. If your container is bigger, your map has wrapped around.

Don't know if the function is meant for this but it works.

这篇关于在Google Maps API V3中获取非包裹地图边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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