Add new marker point each distance

I’m trying to add new points to a route. For example:
The route is 1000km long every 100km add one marked as if it were mandatory stops or goals to be reached on a given route.
But I am not able to find something like that.
API JS

Could you not iterate through the path and add up the distance then once >100km add marker and reset the distance counter.

Not sure on JS application.

1 Like

I believe it would be a solution but I am not able to develop it

Sorry, I’m no good with JS, I can only offer suggestions and not answers. Try reading the following to iterate through path;

Then look up how to add markers to map.

Hopefully it makes more sense to you.

Thank you, I will do a detailed reading and see if I can make any progress.

If you resolve your problem please post your solution as it might help someone with the same query.

2 Likes

I couldn’t create a solution :frowning:

I have the solution that calculates the points in google maps api.
But I can’t create it for graphhoper api js

https://pastebin.com/36cUBXtj

you can make this a bit tidier but…
set a global int variable (outside of the loop) called accumulated_distance, set it to 0
Create a list that can hold “routenodes” or whatever you want
Create an class eg(id, lat,lng, totalDistanceTravelled ,and a binary field called have_break )

loop through your points/nodes ( with an index)
for each one,
create an object of routenodes
set id to the value of your loop index
add the lat and lng ( maybe store a location object)
add Have_break = false into each object
add the object to the list routenodes.

When your loop finishes
Loop through the objects you have created
if the index>0 {
use a location library ( or haversine method) to calculate the the distance between this index’s location and the previous index’s location
eg accumulated_distance = accumulated_distance + ((thislocation)distanceto(index-1 location)
set totaldistancetravelled = accumlated_distance;
}
Now you have a list of points with the distance traveled at each point

set a var called dist_alarm, set it to 100,000 ( 100k meters)
run through list again :slight_smile:

if total distancetravelled > dist_alarm {
have_break==true
distalarm = distalarm + 100000;
}

now you can extract the locations that have have_break=true.

Hello,
I’ll try, thanks for the answer!

Powered by Discourse