thephpleague / geotools

Geo-related tools PHP 7.3+ library built atop Geocoder and React libraries
MIT License
1.36k stars 122 forks source link

Extract points to some distance origin to destination? #142

Open navotera opened 3 years ago

navotera commented 3 years ago

Let say I have set of latitudes and longitude points which would be shaped as line on map which have total distance 20 km.

I want to extract only cordinate from 0 km point to 4 km so it will result by generating new set of lat-long points. In others case I need to extract from 3 km to 6 km.

How can I implement it with this library?

Thank you.

navotera commented 3 years ago

This is a question for StackOverflow.

This can be done with a bit of linear algebra. Note that while the earth is not perfectly round, there isn't a formula that will work 100% for every inch of the earth but the answer below should be fine for almost every application.

https://math.stackexchange.com/questions/2045174/how-to-find-a-point-between-two-points-with-given-distance

See the last answer for a basic version in python, just convert it to PHP

Thank you. I need to wait if this can be achieved with this library.