简体   繁体   English

在Google Maps Directions API提供的现有纬度之间生成新的纬度/经度

[英]Generate new Lat/Lng between existing Lat/Lng provided by Google Maps Directions API

I am using the Google Maps Directions Service to request a path from a start point to an end point. 我正在使用Google Maps Directions Service请求从起点到终点的路径。 This obviously returns a list of Lat/Lng markers which are joined to draw a path. 显然,这将返回纬度/经度标记的列表,这些标记被结合以绘制路径。 The code looks like this: 代码如下:

  directionsService.route(request, function(result, status) {
    if (status == 'OK') {
      directionsDisplay.setDirections(result);
      var myRoute = result.routes[0].legs[0];
      //console.log(myRoute);

      for (var i = 0; i < myRoute.steps.length; i++) {
      var marker = new google.maps.Marker({
        position: myRoute.steps[i].start_point,
        map: map
      });
      console.log(myRoute.steps[i].start_point.lat(),myRoute.steps[i].start_point.lng() );
      attachInstructionText(marker, myRoute.steps[i].instructions);
      markerArray[i] = marker;
  }

    }
  });

在此处输入图片说明

I am having trouble figuring out an algorithm which will generate more Lat/Lng 'markers' between the existing ones. 我在弄清楚将在现有算法之间生成更多纬度/经度“标记”的算法时遇到了麻烦。

To visualize this even further here is another diagram. 为了进一步可视化,这是另一张图。 Red X's show the points that the call returns. 红色X显示呼叫返回的点。 I have then added Blue X's on-top to show what I want the result to look like. 然后,我在顶部添加了Blue X,以显示我希望结果看起来像什么。 在此处输入图片说明

Thanks!!! 谢谢!!!

For each line connecting the red points: 对于连接红色点的每条线:

Use this function to determine the distance between the two points. 使用此功能确定两点之间的距离。 Figure out how close together you want the blue Xs to be - for example, 30m? 弄清楚您希望蓝色X靠近多少距离-例如30m? 50m? 50公尺? Variable depending on zoom? 根据变焦而变化? Using that, determine how many new points you want to come up with between the two endpoints. 使用该值,确定两个端点之间要提出多少个新点。 Then, for each lat/lng, divide the difference between the endpoints by (new points + 1) to come up with how much lat/lng difference each new point should have. 然后,对于每个经度/纬度,将端点之间的差异除以(新点+ 1),得出每个新点应具有的经度/纬度差。

For example: Start with endpoints 例如:从端点开始

Lat 100, Lng 80

and

Lat 110, Lng 60

(distance too large, but this is just an example) Say you do a calculation and find that you need 4 additional points. (距离太大,但这只是一个例子)假设您进行了一次计算,发现还需要增加4个点。 Latitude difference between each point would be: 每个点之间的纬度差为:

(110 - 100) / (4 + 1) = 10 / 5 = 2

Latitude difference between each point would be: 每个点之间的纬度差为:

(60 - 80) / (4 + 1) = -20 / 5 = -4

Generate 4 new points, using those differences to calculate their lat/lng: 生成4个新点,使用这些差异计算其经度/纬度:

(100, 80) (start)
(102, 76)
(104, 72)
(106, 68)
(108, 64)
(110, 60) (end)

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

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