繁体   English   中英

如何使用谷歌地图在2点之间相距1公里的折线上绘制精度为6m的经纬度

[英]How to get lat lng with 6m accuracy on polyline draw between 2 points 1Km apart using google maps

我在相距1公里的两个点之间的地图上绘制了一条折线。 我想以6m的精度获得折线上的纬度,即折线上相距6 m的点的纬度。 我们应该怎么做?

这是用于绘制折线的代码

 // google maps showing polylines between two points function initMap() { var map = new google.maps.Map(document.getElementById('map'), { zoom: 10, center: {lat: 26.138434, lng: 75.783714}, mapTypeId: 'terrain' }); var flightPlanCoordinates = [ {lat: 26.138434, lng: 75.783714}, {lat: 26.091578, lng: 75.830330} ]; var flightPath = new google.maps.Polyline({ path: flightPlanCoordinates, geodesic: true, strokeColor: '#FF0000', strokeOpacity: 1.0, strokeWeight: 2 }); flightPath.setMap(map); } 
 /* Always set the map height explicitly to define the size of the div * element that contains the map. */ #map { height: 100%; } /* Optional: Makes the sample page fill the window. */ html, body { height: 100%; margin: 0; padding: 0; } 
 <div id="map"></div> <!-- Replace the value of the key parameter with your own API key. --> <script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap"> </script> 

对于1000米,您可以将表面假定为平面(作为几何图形),并基于此,您可以简单地使用纬度和经度之差之间的比例,然后循环以构建所有需要添加相关坐标的坐标

  dlat = 26.138434 - 26.091578;
  dlng = 75.830330 - 75.783714;

  addLat = (6*dlat)/1000;
  addLng = (6*dlng)/1000;

  i = 0;
  l = 0;
  while ( l <1000)  {

    myLat[i] = 26.091578 + addLat*i;
    myLng[i] = 26.091578 + addLng*i;
    i++;
    l = l+6;
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM