I'm creating a wild life application. There I have several markers placed in different places in Google Map. I need to trace the route from my current location to the specific marker point when user clicks on that marker.
How can I do this? I don't want user to click on the map without clicking the marker. Please help me with this. Thanks in advance.
What should be written to
mGoogleMap.setOnMarkerClickListener(new OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
return false;
}
});
instead of
@Override
public void onMapClick(LatLng point) {
// Already map contain destination location
if(mMarkerPoints.size()>1){
FragmentManager fm = getSupportFragmentManager();
mMarkerPoints.clear();
mGoogleMap.clear();
LatLng startPoint = new LatLng(mLatitude, mLongitude);
drawMarker(startPoint);
}
drawMarker(point);
// Checks, whether start and end locations are captured
if(mMarkerPoints.size() >= 2){
LatLng origin = mMarkerPoints.get(0);
LatLng dest = mMarkerPoints.get(1);
// Getting URL to the Google Directions API
String url = getDirectionsUrl(origin, dest);
DownloadTask downloadTask = new DownloadTask();
// Start downloading json data from Google Directions API
downloadTask.execute(url);
}
}
});