Get longtitude latitude combination based on distance and degree

前端 未结 2 1704
无人及你
无人及你 2021-02-11 03:56

I am trying to get geo combinations of a grid which is covered a certain area (My city). The grid is 500m * 500m. So I wanna enter starting long/latitude combination,distance (5

2条回答
  •  梦如初夏
    2021-02-11 04:19

    This site has example code for many lat/long/distance/bearing calculations:

    http://www.movable-type.co.uk/scripts/latlong.html

    The formula are:

    lat2 = asin(sin(lat1)*cos(d/R) + cos(lat1)*sin(d/R)*cos(θ))

    lon2 = lon1 + atan2(sin(θ)*sin(d/R)*cos(lat1), cos(d/R)−sin(lat1)*sin(lat2))

    θ is the bearing (in radians, clockwise from north);

    d/R is the angular distance (in radians), where d is the distance travelled and R is the earth’s radius

    The relevant code you are interested in is in javascript, but should be easy to convert:

    var lat2 = Math.asin( Math.sin(lat1)*Math.cos(d/R) + 
                          Math.cos(lat1)*Math.sin(d/R)*Math.cos(brng) );
    var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(lat1), 
                                 Math.cos(d/R)-Math.sin(lat1)*Math.sin(lat2));
    

提交回复
热议问题