我在移动时如何在Google地图上绘制路径?

Mon*_*ali 3 android

我正在尝试在Google地图中绘制路径。我能够在起点和终点之间绘制一条路径,但是我想在移动时绘制路径。当我在Google地图上移动时,请帮助我绘制路径。

谢谢莫纳利

Fla*_*vio 5

注册LocationListener并在onLocationChanged方法中绘制起点和到达点之间的路径。

    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
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)