How to save tracking polylines in database?

前端 未结 1 1691
攒了一身酷
攒了一身酷 2021-01-07 11:37

I have created a function whereby I am able to track the user\'s route and create a polyline. I have been trying to save it to Firebase as - routeId, routeName, lat, lng

相关标签:
1条回答
  • 2021-01-07 11:46

    Firebase would be ideal for storing and retrieving this type of data.

    For example, suppose you have the user enter a route name and id and you want to store waypoints along the path (lat and long for each waypoint) from start to destination:

    One way the data could be stored in Firebase is:

    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"
    

    Within each parent node (random_route_node_name) you have the routeName, the id and then the waypoints along the path, each waypoint has a longitude and latitude.

    A couple of important things to point out.

    The random_route_node_name and random_waypoint_node_name would be names generated with Firebase childByAutoId or some other non-specific name. This is because the name of the node should not be tied directly to the data so the data can be changed without affecting the node name. The same thing goes for the waypoints; the waypoint child data can be modified without affecting the child parent name

    I don't know if functionality is needed to query for waypoints, but if so, other thing that should be done is to flatten this data - the waypoints for each route could be stored in a separate node which would allow for queries for specific waypoints at a high level. For example, a user wants to know all of the waypoints within a radius of their current location.

    As it is, queries could only be done within a specific route.

    0 讨论(0)
提交回复
热议问题