How to save tracking polylines in database?

雨燕双飞 提交于 2019-12-01 13:57:36

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!