0

I've been looking around countless tutorials and stack overflow posts and found nothing on this subject. I'm trying to allow users to set a numerical value (i.e. 5, 10, 15) of miles and then only showing map markers which are within that distance of the users' current location.

So, I have the users location value and I have a database of markers each with their own lat/lng values. What I want to do is:

  • Get users' current location in Lat/Lng.
  • Get the required distance value (5, 10, 15 miles).
  • Get all the map marker location which are 5 miles away from the users' location.
  • Hide all other markers that aren't.

It's pretty standard functionality when using Google Maps as a user but I just can't find any documentation on it at all. Could any provide any helpful links or some sample code?

I've been looking into LatLngBounds and I believe I can use this in my solution. Am I looking down the right path?

WebDevDanno
  • 1,122
  • 2
  • 22
  • 50
  • Driving distance or as the crow flies? –  Apr 06 '14 at 18:18
  • Well driving distance due to the nature of the app. – WebDevDanno Apr 06 '14 at 18:22
  • @JeremyMiller thanks for your help so far. Could you also provide some links for as the crow flies because after more research that may be more helpful :) – WebDevDanno Apr 07 '14 at 00:10
  • Already did... first link in my answer. ;) –  Apr 07 '14 at 00:13
  • To elaborate, calculating direct distance is faster -- you can do it with pure math and the lat/long's. So, doing that first to filter out unnecessary work is important for speed. Afterwards, you can calculate driving distance, but now you don't have to do it for all entries in your DB. –  Apr 07 '14 at 00:15

1 Answers1

0

I would first find the min latitude and longitude and the max latitude and longitude using a distance formula (see http://www.movable-type.co.uk/scripts/latlong.html ). Then use the answers from Android - How to get estimated drive time from one place to another? to find those which match in terms of driving distance (which will be less than or equal to the min/max).

By finding the min/max lat/long, you reduce the overall number of calculations you will need to do.

Community
  • 1
  • 1