Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save route information #17

Closed
cristodcgomez opened this issue May 6, 2014 · 21 comments
Closed

Save route information #17

cristodcgomez opened this issue May 6, 2014 · 21 comments
Labels

Comments

@cristodcgomez
Copy link

Hi, I'm trying to save the data in a database of the routes that i create.

I'm using at the moment getPlan() to pick all the data of the route, but i have some doubts.

  • How can I load this data again in te constructor? I know that I ca store the waypoints and later use it in the initialize, but i don't know if this will give me the same route all the time
  • There is one way to store in de database the planning in JSON and later load this JSON in the constructor?

Maybe there should be a google group forum where to ask this kind of questions, instead using this place.

Thank you in advance! :)

@perliedman
Copy link
Owner

Sorry for a very late reply, but this can be accomplished by storing the waypoints from getWaypoints(), and then later setting them again with setWaypoints(...).

Please refer to the recently published API docs for details: http://www.liedman.net/leaflet-routing-machine/api/#l-routing-control

@cristodcgomez
Copy link
Author

Sorry for my delayed anwer too, but it was related to the OSRM data (sorry for not ask properly)

In my case, I'm interested in store _routes["number_of_route"].coordinates

I don't know if is a easy access for that part, but It would be helpfull to get OSRM information available with a function too

Greetings

@perliedman
Copy link
Owner

When a route is found, the control fires the event routesfound (http://www.liedman.net/leaflet-routing-machine/api/#routingresultevent), which you can listen for and do whatever you need with the route data. It will include coordinates, distances, time and itinerary: http://www.liedman.net/leaflet-routing-machine/api/#iroute

@eigan
Copy link

eigan commented Nov 4, 2014

@cristomc Hi! Did you find a way to store the route info?

My use case is that I want to store a specific route (might be an alternative route) in a database for later use. Trip planning for instance.
It looks like storing the route_geometry returned from OSRM might be best? Then when I want to retrieve the same route later, I just use a different router to fetch the route_geometry from db.

@perliedman
Copy link
Owner

You might want to save the itinerary and the summary as well, since it's not trivial to get those back later.

@eigan
Copy link

eigan commented Nov 4, 2014

hm, yes, good point.

@cristodcgomez
Copy link
Author

hi @eigan , I just saved the waypoints and the routepoints when you are "creating" a route:

_routes.coordinates gives you the whole coordinates(I needed in my case) of the route. But, if you want to save the waypoints of each route, you can save it with getWaypoints(). When you need recover it (to show them) you only need restore the waypoints and create a new instace of route with them

I hope you can use this info ;)

@eigan
Copy link

eigan commented Nov 4, 2014

Thanks for inputs @cristomc :-)

The problem with only storing waypoints is that the route might be different later (new roads, new algorithm for calculating routes, etc). So I figured storing the entire line/geometry would be a better approach in the long run.
_routes.coordinates would store a really huge array, but that might not be that big of a problem as I am imagining maybe.. Think I should just experiment with the data a little bit :-)

@perliedman
Copy link
Owner

If you want to reduce the size of the coordinates, you might want to look at this: https://github.com/jieter/Leaflet.encoded

OSRM already uses this encoding when sending the coordinates over the wire, and L.Routing.OSRM has the decoding function in it.

@eigan
Copy link

eigan commented Nov 4, 2014

Will do, thanks :-)

@tvjmohan
Copy link

Hi eigan,

I would like to know have you solved this . because I too have same requirement. I want to store route related line and points , even after years I need to draw same route as wat it is giving now ... For that I need to store the line related data.

@perliedman
Copy link
Owner

@tvjmohan it's pretty straight forward to store a route as GeoJSON, and you can store that in a database, file or whatever. Displaying GeoJSON on a map later is also very easy.

There's no builtin function for turning a route into GeoJSON in LRM, but I've written several versions of it before.

You can for example use this code, which hasn't been included in the stable version of LRM: https://github.com/perliedman/leaflet-routing-machine/blob/344ff09c8bb94d4e42fa583286d95396d8227c65/src/L.Routing.js

@tvjmohan
Copy link

Hi, I have seen the code. I just want to know how can i get it into javascript variable. i am not sure which method to cal and what code i have to write (or use from ) in my program. Please help me.

@perliedman
Copy link
Owner

Depends a bit on your environment, but you could probably get it to work by copying the two functions in that file into your code.

@tvjmohan
Copy link

Hmmm. I am using Windows... And simple HTML CSS JavaScript project.

I will try it ... If I get it OK else ... I need ur help.

Thank you ..
On 29-Mar-2016 12:34 PM, "Per Liedman" notifications@github.com wrote:

Depends a bit on your environment, but you could probably get it to work
by copying the two functions in that file into your code.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#17 (comment)

@nalbert9
Copy link

nalbert9 commented Apr 7, 2017

Hi ,
I have a problem. I want to get route.coordinates and time associate to a trip ( time, latLng.lng, latLng.lat ). Actually I just have only coordinates and summary.totalTime informations. Need your help, please.

@perliedman
Copy link
Owner

@gfoxx29 it's not clear to me what you're asking. You say you need the coordinates and time, but also that you "only" have the coordinates and the time.

You can always look at how the itinerary is built (L.Routing.Itinerary) for details.

@nalbert9
Copy link

nalbert9 commented Apr 7, 2017

@perliedman
ok, sorry. Actually I know how to get routes.coordinates. But I want someting like

time | coordinates
1.37 | 47.99903 , 3.1699
1.50 | 47.99599, 3.17415

time = the time to get location

@perliedman
Copy link
Owner

@gfoxx29 ok, alright! Look at the instructions property of the route, it is an array of instructions where each instruction contains time as well as distance for that step. See docs for IRoute for more details on what info is in there.

@adustdu2015
Copy link

hi,man ! My project now is about an indoor map route. I have to make a custom route by myself from one room to another room ,but I don't know how to begin making it .please give me some advice.thanks!

@Narimene29
Copy link

Bonsoir tout le monde, j'ai besoin de votre aide s'il vous plait,
J'aimerais savoir si vous avez résolu ce problème. car moi aussi ça fait presque un mois que je bloque sur ça, je veux stocker la ligne et les points liés à un itinéraire (que j'arrive à tracer) dans une base de données que j'ai déjà crée, Merci.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants