【问题标题】:Subtract meters from latitude从纬度中减去米
【发布时间】:2015-06-24 08:35:33
【问题描述】:

通过从给定纬度向南 x 米数来计算新纬度点的最简单方法是什么?例如,埃菲尔铁塔位于48.8582 latitude and 2.2940 longitude。我在塔周围有一个半径为 171 米的圆圈。我想在圆圈下方放置一个 InfoBox。

这是我的圈子:

var circle = new google.maps.Circle({
    map: map,
    fillColor: 'red',
    fillOpacity: 0.2,
    strokeWeight: 1,
    center: new google.maps.LatLng(48.8582, 2.2940),
    radius: 171
});

我的信息框目前定位在圆圈的中心位置,但我希望它直接位于圆圈下方。所以我猜我只需要将盒子(171/2=85.5)米向南移动就可以得到我想要的位置。

这个有简单的计算吗?我看过haversine formula,但这似乎比我需要的要复杂得多,而且我不明白如何使用它,也不知道它是否适合这个问题。

我想准确地向南走 85.5 米,并获取新的纬度/经度坐标来定位信息框。大概只有纬度会改变,但我不确定。

【问题讨论】:

    标签: google-maps coordinates


    【解决方案1】:

    向南 85.5 米非常容易,因为纬度的度数始终以米为单位。地球的周长为 ± 40075 公里,对应于 360 度,因此您的答案是 360 * 85.5 / 40075000 = 0.000768 度。

    【讨论】:

      【解决方案2】:

      您可以使用spherical geometry 计算向南 171 米 computOffset method

      google.maps.geometry.spherical.computeOffset(circle.getCenter(),circle.getRadius(),180)
      

      proof of concept fiddle

      代码sn-p:

      var geocoder;
      var map;
      
      function initialize() {
        var bounds = new google.maps.LatLngBounds();
        geocoder = new google.maps.Geocoder();
        var secheltLoc = new google.maps.LatLng(-27.532861, 134.693340),
          markers,
          myMapOptions = {
            zoom: 7,
            center: secheltLoc,
            mapTypeId: google.maps.MapTypeId.ROADMAP
          };
        map = new google.maps.Map(document.getElementById("map-canvas"), myMapOptions);
      
        var circle = new google.maps.Circle({
          map: map,
          fillColor: 'red',
          fillOpacity: 0.2,
          strokeWeight: 1,
          center: new google.maps.LatLng(48.8582, 2.2940),
          radius: 171
        });
        map.fitBounds(circle.getBounds());
        var boxText = document.createElement("div");
        boxText.innerHTML = "Eiffel Tower<br>48.8582 latitude<br> 2.2940 longitude";
        // Start InfoBox
        //these are the options for all infoboxes
        infoboxOptions = {
          content: boxText,
          disableAutoPan: false,
          zIndex: null,
          maxWidth: 0,
          boxStyle: {
            background: "url('http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/examples/tipbox.gif') no-repeat",
            opacity: 0.85
          },
          closeBoxMargin: "6px 2px 0px 0px",
          closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif",
          infoBoxClearance: new google.maps.Size(1, 1),
          isHidden: false,
          pane: "floatPane",
          enableEventPropagation: false,
          pixelOffset: new google.maps.Size(-50, 0)
        };
      
        //define the text and style for all infoboxes
        boxText.style.cssText = "width: 100px; border: 1px solid #333; margin-top: 3px; background: #fff; padding: 1px; font-size: 11px; white-space:nowrap; padding-right: 20px; color: #333";
      
        //Define the infobox
        var infobox = new InfoBox(infoboxOptions);
        infobox.setPosition(google.maps.geometry.spherical.computeOffset(circle.getCenter(), circle.getRadius(), 180));
        infobox.open(map);
      }
      google.maps.event.addDomListener(window, 'load', initialize);
      #map-canvas {
        height: 400px;
        width: 400px;
      }
      <script src="https://maps.googleapis.com/maps/api/js?libraries=geometry&ext=.js"></script>
      <script src="http://www.staff.org.au/infobox.js"></script>
      <div id="map-canvas"></div>

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-02-21
        • 1970-01-01
        • 2011-07-06
        • 2011-11-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多