【问题标题】:how to get the point2(destinationPoint) with point1(startPoint) in latlng and distance in meters如何在 latlng 中使用 point1(startPoint) 和以米为单位的距离获取 point2(destinationPoint)
【发布时间】:2014-06-24 02:36:43
【问题描述】:

我有一个 latlng 格式的 point1 和一个米格式的距离。现在我的问题是

如何通过point1和距离得到Point2?

我发现了许多相关的问题,只是无法理解他们的扩展讨论。

我只想要简单的 javascript 公式或代码来演示如何进行计算。

非常感谢。


更新:

距离包含2个方向:x和y

从中心偏移 X 米。

Y 米偏离中心。

在这里,中心是point1。 所以

point1 看起来像:-34.127895, 140.56842

距离看起来像:3532米,9211米


更新 2

我快到了,我找到了计算三角形第三(未知)边的公式。 现在我有了 sin(wantedAngel) = sine(90)/(X*Y)。 现在我只想知道如何在 Javascript 中进行 un-sin() 数学运算。 WantedAngel 正在承受。

【问题讨论】:

  • 你不能不知道方向
  • 嗨@paulitto,请查看我的更新,谢谢。
  • 嗨@ChristianVarga 我已经更新了我的问题,谢谢。
  • @Franva 那是因为Math.sin 也接受弧度作为参数。这会给你 90:Math.asin(Math.sin(Math.PI*90/180)) * (180/Math.PI)

标签: javascript google-maps gis


【解决方案1】:

您将无法以简单的方式计算这一点。由于地球不是平坦的表面,纬度和经度不容易转换为米。

查看this 表(这将有助于阅读整篇文章)。可以看到,1 度纬度等于 111.32 公里。向北 23 度只等于 102.47 公里,直到它到达北极点为零。

看看从顶部到底部越来越小的圆圈:

我认为它不会比这里提供的方法容易得多: How to calculate the latlng of a point a certain distance away from another?

【讨论】:

  • 嗨懒汉,谢谢你的回复。这与我的问题非常接近,但只有一件事不同:我没有轴承。我只有一个点格式的距离,其中包含 X 和 Y(从中心偏移的 X 米。从中心偏移的 Y 米。)。
  • @Franva 使用您拥有的值可以计算方位。您的 X 和 Y 信息可以看作是与实际距离形成三角形的两条线。 X 和 Y 以 90 度对齐。现在给定两条边和 90 度,您可以计算三角形的所有其他值并使用链接中提供的解决方案。
  • 你是对的 :) 但是我已经把几乎所有的数学知识都还给了我的老师......你能写几行代码告诉我如何计算方位吗?非常感谢
  • 我快到了,我找到了计算公式。现在我有了 sin(wantedAngel) = sine(90)/(X*Y)。现在我只想知道如何在 Javascript 中进行 un-sin() 数学运算。 WantedAngel 正在承受。
  • 您能提供到目前为止的代码吗?一个 jsfiddle 是最好的。
【解决方案2】:

所有学分都归@geocodezip :)

JavaScript:

function initialize() {
 var map = new google.maps.Map(document.getElementById('map-canvas'), {
  center: new google.maps.LatLng(-34.127895, 140.56842),
        zoom: 6,
        mapTypeId: google.maps.MapTypeId.ROADMAP
  });
  var bounds = new google.maps.LatLngBounds();

  var infowindow = new google.maps.InfoWindow();
  var marker = new google.maps.Marker({
  position: map.getCenter(), 
  map: map
   }); 
    bounds.extend(map.getCenter());
   var south = google.maps.geometry.spherical.computeOffset(marker.getPosition(),3532,180);
    var line1 = new google.maps.Polyline({
        map:map,
        path: [marker.getPosition(),south],
        strokeWeight: 2,
        strokeColor: "#ff0000"
    });
    bounds.extend(south);
  var destination = google.maps.geometry.spherical.computeOffset(south,9211,90);
    bounds.extend(destination);
    var line2 = new google.maps.Polyline({
        map:map,
        path: [south, destination],
        strokeWeight: 2,
        strokeColor: "#ff0000"
    });


    var destMarker = new google.maps.Marker({
      position: destination, 
      map:map
  });    
    map.fitBounds(bounds);
    document.getElementById('info').innerHTML = "distance is "+(google.maps.geometry.spherical.computeDistanceBetween(marker.getPosition(), destination)/1000.0).toFixed(2)+"  km";
    var line3 = new google.maps.Polyline({
        map:map,
        path: [marker.getPosition(), destMarker.getPosition()],
        strokeWeight: 2,
        strokeColor: "#0000FF"
    });
}


google.maps.event.addDomListener(window, 'load', initialize);

HTML

<div id="map-canvas"></div>
<div id="info"></div>

CSS

#map-canvas, html, body {
    height: 95%;
    width: 100%;
}

或者你可以看看:

http://jsfiddle.net/A8yZL/1/

【讨论】:

    猜你喜欢
    • 2012-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-02
    • 1970-01-01
    • 1970-01-01
    • 2020-08-10
    相关资源
    最近更新 更多