2017-05-04 27 views
-3

我正在研究需要記錄用戶路線的應用程序。我只知道如何記錄起點,但我不知道如何去做其餘的事情。請幫忙。如何在用戶走路時記錄路線

我的工作:

ArrayList<LatLng> routeLatlng = new ArrayList<LatLng>();  
Location currentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); 

routeLatlng.add(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude())); 
+1

您需要每5秒重複一次並獲取新位置,將其存儲在一個數組中,然後您就可以準備好應用了! –

+0

正如@SrihariKaranth所說。但是使用一個位置偵聽器,每當用戶移動到足以產生變化或者足夠的時間已經過去時,它將調用所述方法。 – Doomsknight

回答

2

嘗試覆蓋的onLocationChanged方法來記錄路由。它在用戶的當前位置發生變化時進行響應。

@Override 
public void onLocationChanged(Location currentLocation) { 
    routeLatlng.add(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude())); 
} 
+0

謝謝。有用。 –