Calculate endpoint given distance, bearing, starting point

后端 未结 4 672
自闭症患者
自闭症患者 2020-12-06 11:38

I am trying to find the destination point, given a starting point lat/long, bearing & distance. The calculator from this website below gives me the desired results.

4条回答
  •  时光说笑
    2020-12-06 12:02

    very simple solution in geometry library (V3), if you do not have a problema with using the google maps api V3 (depending on the application - realtime asset tracking, for example - the free license is not applicable OR you might not want to refactor from V2 to V3).

    1st: declare an extra library ALONG with your current declaration:

    
    

    2nd: establish starting point, heading and distance

    var nyc = new google.maps.LatLng(40.715, -74.002);
    var distance = 5576673;
    var heading = 51.2145;
    

    3rd: go there

    var endPoint = google.maps.geometry.spherical.computeOffset(nyc, distance, heading);
    var london = new google.maps.Marker({
      position: endPoint,
      map: map
    });
    

    done, you are now in London town. for more info regarding computeDistance, computeHeading and computeArea:

    http://www.svennerberg.com/2011/04/calculating-distances-and-areas-in-google-maps-api-3/

    http://code.google.com/intl/en/apis/maps/documentation/javascript/geometry.html

提交回复
热议问题