-1

I am doing a project where I need to find the closest 10 markers from my current location On Google map in Android. Is there any API or inbuilt function/class that displays these things? I have little bit knowledge of Google Maps in Android.

I need to find 10 closest marked place on google map and its lat long and title in my list view...

Plz Plz Help me out.!

Dharmik
  • 2,325
  • 3
  • 27
  • 37

2 Answers2

4

you need to use following method for finding distance between two geo points.

/**
 * 
 * @param lat1 Latitude of the First Location
 * @param lng1 Logitude of the First Location
 * @param lat2 Latitude of the Second Location
 * @param lng2 Longitude of the Second Location
 * @return distance between two lat-lon in float format
 */

public static float distFrom (float lat1, float lng1, float lat2, float lng2 ) 
{
    double earthRadius = 3958.75;
    double dLat = Math.toRadians(lat2-lat1);
    double dLng = Math.toRadians(lng2-lng1);
    double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
    Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
    Math.sin(dLng/2) * Math.sin(dLng/2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    double dist = earthRadius * c;

    int meterConversion = 1609;

    return new Float(dist * meterConversion).floatValue();
}

Here your first geo codes will be your current Position's geo code and other geo points are the geo points you want to compare with , you need to run a loop for it.

Lucifer
  • 29,392
  • 25
  • 90
  • 143
  • @ Android. Can you see my question ? https://stackoverflow.com/questions/48563909/illegalstateexception-fragment-already-added-android?noredirect=1#comment84192332_48563909 –  Feb 03 '18 at 14:45
1

I don't believe there is a built-in function to retrieve nearby markers in the way you describe, but you should be able to build your own by calculating the distance to each marker and sorting the results.

rjz
  • 16,182
  • 3
  • 36
  • 35