如何在谷歌地图v3中获取多边形的中心? [英] How to get the center of a polygon in google maps v3?
本文介绍了如何在谷歌地图v3中获取多边形的中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
它不需要100%正确,它可以是边界矩形的中心。 解决方案
算法:
运行多边形中的所有点。对于所有的点发现;
-
x1
,最低x
coordinate -
y1
,最低y
坐标 > -
x2
,最高x
坐标 -
y2
,最高y
坐标
你现在有了边界矩形,并且可以使用以下方法计算中心:
center.x = x1 +((x2-x1)/ 2);
center.y = y1 +((y2 - y1)/ 2);
It doesn't need to be 100% correct, it can be the center of the bounding rectangle.
解决方案
Algorithm:
Run through all the points in the polygon. For all the points find;
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屋!
查看全文