如何在谷歌地图 v3 中获得多边形的中心? [英] How to get the center of a polygon in google maps v3?
本文介绍了如何在谷歌地图 v3 中获得多边形的中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
它不需要100%正确,它可以是边界矩形的中心.
It doesn't need to be 100% correct, it can be the center of the bounding rectangle.
推荐答案
算法:
遍历多边形中的所有点.对于所有的点找到;
Run through all the points in the polygon. For all the points find;
x1
,最低的x
坐标y1
,最低y
坐标x2
,最高x
坐标y2
,最高y
坐标
x1
, the lowestx
coordinatey1
, the lowesty
coordinatex2
, the highestx
coordinatey2
, the highesty
coordinate
您现在有了边界矩形,可以使用以下方法计算中心:
You now have the bounding rectangle, and can work out the center using:
center.x = x1 + ((x2 - x1) / 2);
center.y = y1 + ((y2 - y1) / 2);
这篇关于如何在谷歌地图 v3 中获得多边形的中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文