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

How to call L.Routing.control() many times? #676

Open
dev1ninja opened this issue Oct 7, 2022 · 1 comment
Open

How to call L.Routing.control() many times? #676

dev1ninja opened this issue Oct 7, 2022 · 1 comment
Labels

Comments

@dev1ninja
Copy link

Hi.
I am going to add multiple L.Routing.Control() with 50 waypoints into my Map.
Here is my Code

Promise.all(arr).then(values => {
        for (let i = 0; i < Math.ceil(result.length / 50); i++) {
            let arr = result.slice(i * 50, i * 50 + 50)
            setTimeout(() => {
                L.Routing.control({
                    waypoints: [startLocation, ...arr],
                    show: false,
                }).on('routeselected', function (e) {
                    let route = e.route;
                    wb.SheetNames.push(`OSRM${i}`)
                    console.log("Route Result sub: ", route)
                    const ws_data = [
                        [
                            "Type",
                            "Distance",
                        ],
                        ...route.instructions.map(item => [
                            item.type,
                            item.distance,
                        ])
                    ]
                    let ws = XLSX.utils.aoa_to_sheet(ws_data);
                    wb.Sheets[`OSRM${i}`] = ws;
                }).addTo(map);
            }, i*1000)
        }
    })

As you can see on my code ->
I'm trying to set many L.Routing.Control()(more than 500) with 50 waypoints in my map.
So in this case, I need to send the requests to Nominatim Server to get the Routing result and Geocoding data.
I should send more than 2000 requests in a time, but I can see, if I do like that, my IP has been blocked.
How can I solve this problem?
Also I would like to know how can I use Paid Version. Where can I subscribe and get API key?
Thanks in advance

@curtisy1
Copy link
Collaborator

curtisy1 commented Oct 7, 2022

Hey, 500 controls seems a bit excessive. What do you need them for exactly?

I should send more than 2000 requests in a time, but I can see, if I do like that, my IP has been blocked.

Nominatim, or the publicly available OSM servers aren't really made for heavy use. Their usage policy explicitly states that doing the same requests over and over will eventually get you blocked

How can I solve this problem?

If you want to continue using nominatim and OSRM, you need to set up your own instances.
For testing purposes, I recommend a docker instance but you can also use a dedicated server and follow the installation instructions. Same goes for OSRM

The other option, as you mentioned is using a paid service like Mapbox or GraphHopper which might get you a few more leeway in the amount of requests

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

2 participants