如何在谷歌地图v3中获取多边形的中心? [英] How to get the center of a polygon in google maps v3?

查看:141
本文介绍了如何在谷歌地图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 lowest x coordinate
  • y1, the lowest y coordinate
  • x2, the highest x coordinate
  • y2, the highest y 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屋!

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