Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get nearby city or state name of a geopoint in water in ios?

I am developing a location-based application in which I need to get nearby location name of any geopoint selected by user. I'm using Google Places API which is working fine for me.

Only problem is the service returns null for geopoints in water. Is there any way that I can retrieve nearby locations for a geopoint in water or ocean?

like image 321
rahul Avatar asked Nov 01 '22 00:11

rahul


1 Answers

AFAIK the API has no way to do that. So, you've got two options, in order of the effort it takes:

  1. When user taps water just throw a dialog saying "Please select a
    point on land"
    . Next to no effort and will slightly annoy the user.
  2. Try to find the closest land geopoint yourself and use it to run the API request on (instead of the original point). Below are some ideas on that.

A good approach can be based on this answer: basically you can get a KML file with land polygons. For performance reasons, you can simplify the polygons to the extent that makes sense for your zoom levels. Now if your point is in one of those polygons -- it's sea. And you can simply iterate over all polygon edges and pick the one that's closest to your point, then pick a point on it - again closest to your point - and do one little epsilon-sized step towards the outside of the polygon to get a land point you can do a geocode request on. Also, the original author suggests you can use Haversine formula to determine neares land point -- I'm not really familiar with the appliance of that one.

The downside is, you have to deal with KML, iterate over a lot of polygons and optimize them (and lose precision doing that, in addition to possible differences between marineregions.org data and Google Places data)

Another cool trick you could try is using Sobel Filter [edge detection] on the visible map fragment to determine where coastline is (although you will get some false positives there), then trace it (as in raster->vector) to get some points and edges to calculate the closest land position with, in a manner similar to the former approach. Here's a clumsy drawing of the ideaenter image description here

For Sobel edge detection, consider GPUImage lib -- they have the filter implemented and it's probably going to work crazy fast since the lib does all the calculations on GPU.

UPD Turns out there's also a service called Koordinates that has coastline data available, check the answer here

like image 68
Ivan Bartsov Avatar answered Nov 12 '22 13:11

Ivan Bartsov