Get latitude longitude from google maps itinerary

允我心安 提交于 2019-12-13 02:58:50

问题


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

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

  • (latitude,longitude, 0)
  • (latitude,longitude, 1)
  • (latitude,longitude, ...)
  • (latitude,longitude, 99)

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

  1. You select the start of your trip
  2. You select the destination of your trip
  3. It suggest what you can do near your itinerary

回答1:


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:

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

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.

Example:

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


来源:https://stackoverflow.com/questions/24527772/get-latitude-longitude-from-google-maps-itinerary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!