Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在数据库中保存跟踪多段线?_Android_Firebase_Google Maps Android Api 2 - Fatal编程技术网

Android 如何在数据库中保存跟踪多段线?

Android 如何在数据库中保存跟踪多段线?,android,firebase,google-maps-android-api-2,Android,Firebase,Google Maps Android Api 2,我创建了一个函数,通过该函数,我可以跟踪用户的路线并创建多段线。我一直在努力把它保存到Firebase -routeId、routeName、lat、lng 我使用的方法是,每次位置更改时,用户的新lat和long都将保存到Firebase中,Firebase是用户设置的路由名称(当前)和静态路由ID if (mCurrentLocation != null) { String newLat = String.valueOf(mCurrentLocation.getLatitu

我创建了一个函数,通过该函数,我可以跟踪用户的路线并创建多段线。我一直在努力把它保存到Firebase -routeId、routeName、lat、lng

我使用的方法是,每次位置更改时,用户的新lat和long都将保存到Firebase中,Firebase是用户设置的路由名称(当前)和静态路由ID

 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);
    }
我得到的是“route”的每个子级的列表视图,这意味着如果我设置的routeName是“Walking”,则会有一个充满“Walking”的列表。
我想将同一routeName的所有lat和Long保存在一起,然后在listview中检索它们,这样当用户选择routeName时,我可以使用数据库中的lat和lngs重新生成地图上的多段线。这能做到吗?我不介意不使用Firebase,但在线服务器更适合备份。

Firebase非常适合存储和检索此类数据

例如,假设您让用户输入路线名称和id,并且您希望存储从起点到终点的路径(每个航路点的纬度和长度)上的航路点:

将数据存储在Firebase中的一种方法是:

random_route_node_name
  routeName: "a route name"
  routeId: "some route id"
  waypoints
      random_waypoint_node_name
        lat: "latitude"
        lon: "longitude"
      random_waypoint_node_name
        lat: "latitude"
        lon: "longitude"
random_route_node_name
  routeName: "a route name"
  routeId: "some route id"
  waypoints
      random_waypoint_node_name
        lat: "latitude"
        lon: "longitude"
      random_waypoint_node_name
        lat: "latitude"
        lon: "longitude"
在每个父节点(随机路由节点名称)中,您有routeName、id,然后是路径上的航路点,每个航路点都有经度和纬度

有几件重要的事情需要指出

随机_路由_节点_名称和随机_航路点_节点_名称将是使用Firebase childByAutoId或其他非特定名称生成的名称。这是因为节点的名称不应直接绑定到数据,因此可以在不影响节点名称的情况下更改数据。同样的道理也适用于航路点;可以修改航路点子数据,而不影响子父名称

我不知道是否需要查询航路点的功能,但如果需要的话,应该做的另一件事是将这些数据展平——每条路线的航路点可以存储在一个单独的节点中,该节点允许在较高级别上查询特定的航路点。例如,用户希望知道其当前位置半径内的所有航路点

实际上,查询只能在特定的路由内完成

random_route_node_name
  routeName: "a route name"
  routeId: "some route id"
  waypoints
      random_waypoint_node_name
        lat: "latitude"
        lon: "longitude"
      random_waypoint_node_name
        lat: "latitude"
        lon: "longitude"
random_route_node_name
  routeName: "a route name"
  routeId: "some route id"
  waypoints
      random_waypoint_node_name
        lat: "latitude"
        lon: "longitude"
      random_waypoint_node_name
        lat: "latitude"
        lon: "longitude"