API – Google Maps JS API v3 Polygon Formation Guide

apigooglemaps

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?

Best Answer

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.

Related Question