How to draw a path on google map while i am moving?

I am trying to draw a path on a google map. I can draw a path between the start point and the end point, but I want to draw a path while I move. Please help me draw a path when I navigate the google map.

Thanks Monali

+2
source share
2 answers

Register a LocationListener and in the onLocationChanged method draw a path between the starting point and the point that came.

    private void addLocationListener(LocationListener locationListener) {
    LocationProvider locationProvider = getLocationManager().getProvider(LocationManager.GPS_PROVIDER);

    getLocationManager().requestLocationUpdates(locationProvider.getName(), LOCATION_UPDATE_INTERVAL,
            LOCATION_UPDATE_MIN_DISTANCE, locationListener);
}

private LocationManager getLocationManager() {
    return (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
}

private void startGpsListening(Location start) {
   this.startLocation = start;
   addLocationListener(new MyLocationListener());
}

private Location startLocation = new Location("");

private class MyLocationListener extends LocationListener {

    public void onLocationChanged(Location location) {
        Log.d(LOG_TAG, "New location has come: " + location);
        // draw path between startLocarion and this location
    }
    ...
}
+4
source

Collect the last N points in the array. Each time you update the array, redraw all the values. Use Overlay to draw a line.

0
source

All Articles