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

查看:25
本文介绍了如何在谷歌地图 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 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天全站免登陆