我已經創建了一個函數,可以跟蹤用戶的路線並創建一條折線。我一直在嘗試將它保存到Firebase中,因爲我使用的方法是,每次在位置更改時,用戶的新lat和long都將保存到Firebase中,routeName,routeName,lat,lng如何在數據庫中保存跟蹤多義線?
用戶已設置和(當前)靜態routeId。
if (mCurrentLocation != null) {
String newLat = String.valueOf(mCurrentLocation.getLatitude());
String newLng = String.valueOf(mCurrentLocation.getLongitude());
LatLng newPoint = new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude());
List<LatLng> points = route.getPoints();
points.add(newPoint);
route.setPoints(points);
Map<String, String> routePoint = new HashMap<String,String>();
routePoint.put("routeID", "124");
routePoint.put("routeName", saveRouteTitle);
routePoint.put("lat", newLat);
routePoint.put("lng", newLng);
mFirebaseRef.push().setValue(routePoint);
}
然而,當我使用的適配器,像這樣,
@Override
protected void populateView(View view, Route route) {
// Map a Chat object to an entry in our listview
String routeName = route.getRouteName();
int routeID = route.getRouteID();
String lat = route.getLat();
String lng = route.getLng();
TextView tvRouteName = (TextView) view.findViewById(R.id.tvRouteName);
tvRouteName.setText(routeName + ": ");
}
什麼,我得到的是「路線」的每一個孩子,這意味着如果routeName我已經設置的列表視圖檢索數據是"Walking"
,會出現一個充滿「散步」的列表。 我想一起保存相同routeName的所有緯度和長度,然後在列表視圖中檢索它們,因此當用戶選擇routeName時,我可以使用數據庫中的lat和lngs重新生成地圖上的折線。這可以做到嗎?我不介意不使用Firebase,但在線服務器對於備份更爲理想。
傑伊回答! –