Calculate point between two coordinates based on a percentage

前端 未结 3 864
面向向阳花
面向向阳花 2021-01-02 16:53

I am looking for a function that returns a point (lat, long) between two points (where I also specify their lat, long) and that point is based on a distance percentage.

3条回答
  •  感情败类
    2021-01-02 17:18

    Assuming the coordinate is a decimal number. You can use this equation.

    function midpoint(lat1, long1, lat2, long2, per) {
         return [lat1 + (lat2 - lat1) * per, long1 + (long2 - long1) * per];
    }
    

    Return a new desired coordinate of [lat, long], based on the percentage (such as per=0.2 for 20%).

提交回复
热议问题