5

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?

gacrux
  • 930
  • 1
  • 9
  • 16

2 Answers2

4

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?

zdav
  • 2,752
  • 17
  • 15
  • Thanks, searching is much easier with the correct terminology. It's part of a PHP import script, so I would prefer to keep it in PHP. – gacrux Jun 10 '10 at 01:52
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

zerkms
  • 249,484
  • 69
  • 436
  • 539