简体   繁体   中英

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

I have a polyline drawn on a map between two points which are 1 KM apart. I want to get the lat long on the polyline with 6m accuracy ie lat long of points on the polyline which are 6 m apart. How can we do this?

Here is the code to used to draw the polyline

 // 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> 

for 1000 meters you can assum the surface as plain (as a geometry) and based on this you could simply use a proportion between difference of lat and lng then loop for build all the coords you need adding the related step

  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;
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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