In my Map Activity i'm displaying few Markers indicating parking lots and i have an ImageView showing a car icon which is fixed to center of the screen on top of the the Map Fragment. I want to perform some action when the car icon overlaps parking_lot Marker while dragging the Map.
What are the possible ways of doing this?
I'm able to get the LatLong of the car while dragging but i have no idea what to do next.
you can get center of map with this
Map.getCameraPosition().target;
then you can find distance between users location and center with this method:
private static double distance(double lat1, double lon1, double lat2, double lon2) {
double theta = lon1 - lon2;
double dist = Math.sin(Math.toRadians(lat1)) * Math.sin(Math.toRadians(lat2)) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.cos(Math.toRadians(theta));
dist = Math.acos(dist);
dist = Math.toDegree(dist);
dist = dist * 60 * 1.1515;
return (dist * 1.609344);
}
if distance is lower than a specific value do what you want