CartoDB / mobile-sdk

CARTO Mobile SDK core project
https://carto.com/docs/carto-engine/mobile-sdk/
BSD 3-Clause "New" or "Revised" License
184 stars 65 forks source link

Distance from the current location to nearest sea shore #494

Open binu8051 opened 2 years ago

binu8051 commented 2 years ago

Hi my app is used by the fishermen and i need to alert them when they come closest to the sea shore. for example 1kilometer. How to calculate the distance between the current location to nearest sea shore? which map i need to use, now i am using this as basemap https://github.com/CartoDB/mobile-android-maps-app/blob/master/maps-app/src/main/assets/world-carto.streets-z0-4.mbtiles Thanks

binu8051 commented 2 years ago

any tips please.

mtehver commented 2 years ago

Do you have separate data set for the shoreline or do you intend to use vector tiles? If you have a separate dataset (a GeoJSON file, for example), you can probably use 'search API' of the SDK and simply set search radius to 1KM. If you want to reuse vector tiles, then I think this is not currently possible, as shoreline (land) is not explicitly encoded in the tiles.

binu8051 commented 2 years ago

Thanks, i can find the coatline GeoJSON file from here https://github.com/OSGeo/PROJ/blob/master/docs/plot/data/coastline50.geojson

Can i get some sample codes for the search API. BTW my app is completely offline app.

mtehver commented 2 years ago

@binu8051 Here are roughly the steps you need to do:

  1. Create FeatureCollection from your GeoJSON
  2. Create FeatureCollectionSearchService instance using your feature collection
  3. Create SearchRequest specifying your GPS position as geometry and defining proper search radius (1000m in your case)
  4. Call findFeatures method of search servive using your search request and check whether the result is empty or not.

Note that the result will contain the nearest shoreline segment (if within your search radius), but you will not get the nearest point in the result. Also, the search could be slow and should be done in a background thread.