So my big question here is how does the Google Maps API determine the "inner" versus the "outer" for a filled polygon?

Playing around with the polygon creator @ http://www.the-di-lab.com/polygon/ there seems to be a preference to:

  1. wrap the north pole;
  2. take the "smallest" polygon possible?

The big reason I want to know is to assist with answering the question "is point (x,y) in multipolygon z?"


2 Answers 2


The big reason I want to know is to assist with answering the question "is point (x,y) in multipolygon z?"

Using a Ray casting algorithm to solve the point in polygon problem, you don't need to know how the Google Code works.

enter image description here

The number of intersections for a ray passing from the exterior of the polygon to any point, if odd, shows the point lies inside the polygon. If even, the point lies outside the polygon. This test also works in three dimensions.

  • This begs the question, though: to get started with ray casting, you need to have a point that is known to be in the "exterior." For planar polygons that's easy: the exterior is unbounded. For spherical polygons there is no definite answer: either component can be taken as the exterior. Therefore there must either be a conventional determination of the exterior (which is usually done by means of the orientations of the polygon's rings) or an explicit indication of the exterior in the polygon's representation.
    – whuber
    Jun 8, 2011 at 13:04
  • the 2D methodology is fine, however a 3D surface (such as the earth) requires a more accurate methodology in order to deal with the -180 to 180 of the longitude in addition to the issue of which side of a polygon is filled and which one isn't.
    – jufemaiz
    Jun 13, 2011 at 7:25
  • Maybe you could clarify your question by adding that you are working with global datasets in lat/lon.
    – underdark
    Jun 13, 2011 at 10:16

for v2 it was the GPolygon.contains() method


now v3 supports donut polygons

http://gmaps-samples-v3.googlecode.com/svn/trunk/poly/pentagon.html this takes the first set of coordinates as the inner ring.

  • 1
    thanks for the reply. I have inspected to the polygon methodology for gmaps v3 however it is not so much as first and second (I believe that it is the second set that is the inner ring) but rather the rotation. While this is acceptable at a small level once I start attempting to ensure all test cases are true I run into trouble (mainly around the definition of the inner v outer of a large polygon projected onto the earths surface as with Gmaps).
    – jufemaiz
    Jun 13, 2011 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.