0

I want to check if the current location of the user is in a certain radius to a marker. Should I do it with distanceBetween()? What arguments do I have to pass this function and what exactly does the result say?

LatLng markerPosition = marker.getPosition();
myLocation = locationManager.getLastKnownLocation(provider);
double latitude = myLocation.getLatitude();
double longitude = myLocation.getLongitude();

distanceBetween(???);

 public static void distanceBetween (double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results) {

}
maidi
  • 3,219
  • 6
  • 27
  • 55

2 Answers2

2

you can simple use

distanceTo(Location location)

from Location class todo this, like:

Location makerLoc = new Location("marker");
markerLoc.setLatitude(markerPosition.latitude);
markerLoc.setLongitude(markerPosition.longtitude);
float meters = myLocation.distanceTo(markerLoc);
fmt.Println.MKO
  • 2,065
  • 1
  • 17
  • 25
0

Please use Google Maps Utility Library

This library provide very simple distance calculating just like you need

In example:

computeDistanceBetween() – Returns the distance, in meters, between two 
latitude/longitude coordinates.

computeHeading() – Returns the bearing, in degrees, between two 
latitude/longitude coordinates.

computeArea() – Returns the area, in square meters, of a closed path on the 
Earth.

interpolate() – Returns the latitude/longitude coordinates of a point that 
lies a given fraction of the distance between two given points. You can use 
this to animate a marker between two points, for example.
Adam Fręśko
  • 1,064
  • 9
  • 14