[GIS] Finding the Nearest Landmass to A Point In The Ocean via API

google mapsios

I'm building an iPhone app that often ends up in a point that is in the middle of the ocean. I want to be able to find the nearest landmasses, which in some casses are thousands of miles away.

So far I've thought of calling the maps API on the regions NW, NE, SW, SE – i.e. the ocean coordinate +10 lat, +10 long etc. until I come up with a response that isn't ZERO_RESULTS (I could obviously keep expanding the bounding box until I found something). I'm currently trying to find info on the antipode to San Francisco, which is approximately -37, 56.

The clear limitation on this is that it is in no way scalable, since Google has a request limit of 2,500 per day and I would probably be making 4+ of them per entry by a user (and I expect a user to make at least a few of these requests per use).

Any thoughts?

Thanks, Alex

Best Answer

Look at the "DISTANCE POINT TO POLYLINE OR POLYGON Demo" at:

[This is a Google Maps V2 not v3 demo]

http://www.bdcc.co.uk/Gmaps/BdccGmapBits.htm

SO if you have a polygon/polyline of the sea you can quickly find the distance from a point in the sea - it the reverse of this demo. Data (Coastline) can be downloaded and added to Fusion Tables http://www.ngdc.noaa.gov/mgg/shorelines/gshhs.html

"This uses some 3D geometry maths to work out the distance between the mousepointer's lat/lng and a GPolyline (or border of a GPolygon). The distance in metres is displayed in a panel on the bottom right of the map.

You can test this by panning the map so that a vertex of the polyline lies on one end of the scale bar and then moving the mousepointer to the other end of the scale bar. Also, if you zoom well in, then the distance should stay around 1m or less as you move the mousepointer all along the polyline. The test polyline has horizontal and vertical sides of 2km so the furthest away you can get inside its square is 1000m.

Source code for the distance calculation is available too.

This code can be used for determining how far 'Off Route' a point is or for filtering 'Points Of Interest' for proximity to a route. I have used it with the GSHHS data set to find out how far it is to the sea.

There is a similar, better demo here http://wtp2.appspot.com/cSnapToRouteDemo.html