perliedman / leaflet-routing-machine

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

Import places and get routes from Excel(there is address in CSV) Spread Sheet in OSRM #672

Closed dev1ninja closed 1 year ago

dev1ninja commented 1 year ago

Hi. I'm trying to load places and get routes from CSV that includes array of addresses in OSRM. Is there any special API or library for about this? Also I attached my sample CSV. sample.csv Please help me.

curtisy1 commented 1 year ago

Hi there!

Could you elaborate a bit more on what you want to achieve with that csv? Is the data in there from OSRM and you want to do routing between these addresses? Or do you want to correlate the addresses with OSRM to get the coordinates?

dev1ninja commented 1 year ago

Hi @curtisy1 I want to do routing between those addresses when I upload it. --- OSRM does not accept the addresses, I think. So I think, first I should convert addresses to Coordinates, and then pass it to OSRM to do routing. But I don't know how I do it. Please help me. Thanks

curtisy1 commented 1 year ago

So I think, first I should convert addresses to Coordinates, and then pass it to OSRM to do routing. That's correct. You'll need some kind of geocoder.

You can create a hack with LRM that relies on empty waypoints to achieve this, I believe.

If you initialize LRM as usual, you should have an add button like in the geocoder sample. Clicking that adds an empty waypoint that you can manipulate and geocode.

// L.Routing.control() init
// const csvData = ...
for (const data of csvData) {
    // add a new waypoint
    document.querySelector(".leaflet-routing-add-waypoint").click();

    // fill the newly created input with content
    const geocoders = [...document.querySelectorAll(".leaflet-routing-geocoder")];
    const emptyGeocoder = geocoders[geocoders.length - 1];
    emptyGeocoder.value = data;
}

Something along the lines of this might work

dev1ninja commented 1 year ago

Great! It works for me. Thanks!