gpt4 book ai didi

javascript - 从谷歌地图行程中获取纬度经度

转载 作者:行者123 更新时间:2023-12-03 12:18:59 25 4
gpt4 key购买 nike

我想知道是否有人可以帮助我解决这一问题。

我有一个基于谷歌地图的脚本来计算行程。我想知道是否可以获取此行程的数组,例如每 1 公里的经纬度。如果行程长100公里,我将得到一个包含100个数据的数组

  • (纬度,经度,0)
  • (纬度,经度,1)
  • (纬度、经度、...)
  • (纬度、经度、99)

我需要它,因为我想建议行程附近的积分兴趣。示例:https://roadtrippers.com/

  1. 您选择旅程的起点
  2. 您选择旅行目的地
  3. 它建议您在行程附近可以做什么

最佳答案

DirectionsService 类将为您提供 DirectionsResult object 的响应。该对象有一个名为 overview_path 的属性,从文档中可以看出:

An array of LatLngs representing the entire course of this route. The path is simplified in order to make it suitable in contexts where a small number of vertices is required (such as Static Maps API URLs).

您可以使用它们执行地点搜索(使用 places library )以获取 overview_path 数组中返回的每个 LatLng 半径范围内的兴趣点等。

示例:

var request = {
origin: start_point,
destination: end_point,
travelMode: google.maps.TravelMode.DRIVING
};

var directionsService = new google.maps.DirectionsService();
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
var path = (response.routes[0].overview_path);
}
});

关于javascript - 从谷歌地图行程中获取纬度经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24527772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com