Solving the Point in Polygon Problem Using Google Maps and Fusion Tables

Unfortunately none of the google api's support this query beyond simple rectangles or circles.

Your options are to pre-process using QGIS or the OGR API. Or you can implement the ray casting algorithm in JavaScript.

Also - check out the source of this example: http://www.geocodezip.com/v3_collection-map2e_FT.html

If you implement the algorithm yourself I'm not sure if you can use the loaded shapefile polygons as you would need access the coordinates but there are other ways around that issue.


As GeoSpatialpython.com mentioned, javascript based ray-casting is a good choice. Here is a script from tparkin : https://github.com/tparkin/Google-Maps-Point-in-Polygon/blob/master/maps.google.polygon.containsLatLng.js

It extends the google maps api v3 polygon class with a new method called containsLatLng which accepts a single LatLng object, which represents the point that you are actually checking against the polygon.

To import a shapefile into Fusion Tables, use http://www.shpescape.com/ which is really easy to use. After you are done importing, you can see that the polygons, stored in your shapefile are now in your Fusion Tables table in KML format.

Here comes the tricky part. Use Google Visualization query in Javascript, and with that query choose the polygons that you want to inspect. By this query, the KML formatted text will also be in the result set. Put that in a variable and put that variable between two string: <Placemark> </Placemark> (You can find some tutorials on the web about how to make google polygons from KML using Javascript) And finally, if you managed to transform that KML into a google maps api polygon object, you will be good to go with the ray casting algorithm.

If there is anything you don't understand or need help with, just shoot me a message here!