从谷歌地图行程获取纬度经度 [英] Get latitude longitude from google maps itinerary

查看:35
本文介绍了从谷歌地图行程获取纬度经度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人可以帮助我解决这一点.

I would like to know if someone can help me about this point.

我有一个基于谷歌地图的脚本来计算行程.我想知道是否有可能获得此行程的数组,例如每 1 公里的经纬度.如果行程是100公里,我会得到一个有100条数据的数组

I have a script based on google maps who calculate itinerary. I would like to know if it is possible to get an array of this itinerary with the latitude-longitude every 1 kilometer for example. If the itinerary is 100 kilometers long, i'll get an array with 100 datas

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

我需要它,因为我想在行程附近提出兴趣点.示例:https://roadtrippers.com/

I need it because i would like to propose points interest near an itinerary. Example: https://roadtrippers.com/

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

推荐答案

DirectionsService 类会给你一个 DirectionsResult 对象.这个对象有一个名为 overview_path 的属性,它从文档中给出:

The DirectionsService class will give you a response with a DirectionsResult object. This object has a property called overview_path that gives, from the docs:

代表这条路线整个路线的 LatLng 数组.这路径被简化,以使其适用于以下情况需要少量顶点(例如静态地图 API 网址).

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).

您可以使用这些来执行地点搜索(使用地点库)从 overview_path 数组中返回的每个 LatLng 获得半径范围内的兴趣点等.

You can use these to perform places searches (with the places library) to get points of interest, etc, within a radius from each LatLng that's returned in the overview_path array.

示例:

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

这篇关于从谷歌地图行程获取纬度经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆