0

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);
            }                   
        }
    });     
  • did you tried anything for this? – yuva ツ Aug 11 '14 at 05:25
  • Yes. I found a tutorial. But you have to click on the map to the trace the route. when I addopted that with my app, it clears all the markers as well. I want to trace the route when clicking on the marker. this is the example I used. http://wptrafficanalyzer.in/blog/drawing-driving-route-directions-between-two-locations-using-google-directions-in-google-map-android-api-v2/ – Thurul Nilnuwan Aug 11 '14 at 05:27

1 Answers1

0

Try it -

map.setOnMarkerClickListener(new OnMarkerClickListener() {

            @Override
            public boolean onMarkerClick(Marker mark) {

        }
   }
yuva ツ
  • 3,707
  • 9
  • 50
  • 78