Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Some usefull functions when you work with path/direction in google maps API
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src
test
README

README

Javascript library that offer some usefull function when you work 
with path/directions/routes in Google Maps API, under LGPL Licence.

// Simply create a point on Paris and Zurich centers
var paris = new google.maps.LatLng(48.856667,2.350987);
var zurich = new google.maps.LatLng(47.369024,8.538033);

// Now retrieve a Bounds object that surround all paris.
// ie a square of 10km with $paris as center
var parisRectangle = paris.getRadialBoundaries(5);

// Simply get the straight distance between Paris and Zurich, result in kilometers
// Something around 490km
var paris_zurich_distance = paris.distanceFrom(zurich);

// Then, retrieve the point at 140km between Paris->Zurich (on a straight line)
// Again, distance is in kilometers
// This point is near "Troyes" french city.
var somewhereNearTroyes = paris.pointBetween(zurich,140);

// Retrieve the route from Paris to Zurich
var request = {
  origin: paris,
  destination: zurich,
  travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
  if (status != google.maps.DirectionsStatus.OK) return;
  var leg = response.routes[0].legs[0];
  
  // Once we get that result, compute the point at one hour on the road from Paris to Zurich :)
  var oneHoursFromParisOnTheRoadToZurich = getDirectionPointAtDuration(leg,1*60*60);
  
  // Or the point at the middle of the trip
  // Not the middle in term of kilometer, but in times!
  var middleInTimeFromParisOnTheRoadToZurich = getDirectionPointAtDuration(leg,leg.duration.value/2);
  
});
Something went wrong with that request. Please try again.