perliedman / leaflet-routing-machine

Control for routing in Leaflet
https://www.liedman.net/leaflet-routing-machine/
Other
1.08k stars 351 forks source link

Save route information #17

Closed cristodcgomez closed 10 years ago

cristodcgomez commented 10 years ago

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.

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

Thank you in advance! :)

perliedman commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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 commented 9 years ago

@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 commented 9 years ago

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

eigan commented 9 years ago

hm, yes, good point.

cristodcgomez commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

Will do, thanks :-)

tvjmohan commented 8 years ago

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 commented 8 years ago

@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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 https://github.com/perliedman/leaflet-routing-machine/issues/17#issuecomment-202747861

nalbert9 commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

@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 commented 6 years ago

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 commented 3 years ago

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.