# Google Maps JS API v3 - Polygon formation

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?"

Thoughts?

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.

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. 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. Jun 13, 2011 at 7:25
• Maybe you could clarify your question by adding that you are working with global datasets in lat/lon. Jun 13, 2011 at 10:16

for v2 it was the `GPolygon.contains()` method

http://econym.org.uk/gmap/example_inside.htm

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.

• 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). Jun 13, 2011 at 7:26