Computing latitude longitude center point of a Polygon in PHP

眉间皱痕 提交于 2019-12-23 10:25:56

问题


I have a set of points (stored as lat/lon) for a polygon, I want to compute the lat/lon center point of the polygon in PHP.

Basically to do the same thing as the getCenter() function in Google Maps LatLngBounds.

Any ideas on how I can achieve this?


回答1:


What you are looking for is the centroid of the polygon - which is pretty easy to compute. If you are using latitude/longitude the matter is complicated by the fact the the polygon is actually on the surface of a sphere (ellipsoid).

As an aside, why not just look at the Google api javascript code?




回答2:


You can simply find a lot of formulas with the google queries "center of gravity polygon" or "polygon centroid"

The sample from Wikipedia: http://en.wikipedia.org/wiki/Centroid



来源:https://stackoverflow.com/questions/3011012/computing-latitude-longitude-center-point-of-a-polygon-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!