如何让Google地图显示整个多边形? [英] How do I get Google Maps to show a whole polygon?

查看:147
本文介绍了如何让Google地图显示整个多边形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组GPolygon对象附加到我的域模型中的对象,并添加到我的页面上的地图中。域对象显示在同一页面的列表中,当用户点击其中一个时,我想显示相关的多边形。



我想要整个多边形要显示,理想情况下我希望地图以多边形中心为中心。



我希望会有地图API调用......

  myMap.makeSureYouCanSeeAllThisPolygon(aPolygon); 

但我一直找不到。

如果我必须手动执行此操作,那么很明显我可以很容易地找出对中情况,但我如何计算缩放比例?

解决方案

您可以通过使用 aPolygon.getBounds()。获取多边形的中心点getCenter ); ,然后使用 myMap.setCenter()方法返回的 GLatLng

要获得缩放级别,您可以使用 myMap.getBoundsZoomLevel(aPolygon.getBounds()); 然后使用这与 myMap.setZoom()方法。


I have a set of GPolygon objects which are attached to objects in my domain model and are added to a map on my page. The domain objects are being shown in a list on the same page and when the user clicks on one of them I want to show the associated polygon.

I want the whole polygon to be showing and ideally I want the map to be centred on the polygon centre.

I was hoping that there would be a maps API call along the lines of...

myMap.makeSureYouCanSeeAllThisPolygon(aPolygon);

but I haven't been able to find one.

If I have to do this manually, then I can obviously figure out the centering easily, but how do I figure out the zoom?

解决方案

You can get the centre point of a polygon by using aPolygon.getBounds().getCenter(); and then using the GLatLng returned with the myMap.setCenter() method.

To get the zoom level, you can use myMap.getBoundsZoomLevel(aPolygon.getBounds()); then use this with myMap.setZoom() method.

这篇关于如何让Google地图显示整个多边形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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