perliedman/leaflet-routing-machine

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

dev1ninja opened this issue · 4 comments

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.

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?

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

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

Great!
It works for me.
Thanks!