4

Just curious if anyone knows how to implement the "measure distance" feature found in google maps to the google maps api.

I would like to be able to right-click and have the same functionality that google maps has... any tips?

Thanks!

Mark Reimer
  • 41
  • 1
  • 2
  • I presume you want a function that takes a pair of lat/longs and computes the distance? – Harold Ship Mar 19 '15 at 22:40
  • Yes, and I've seen other people make something, but what I want is the default builtin distance measure that google maps now has... I'm kind of surprised they haven't integrated it into the api. – Mark Reimer Mar 20 '15 at 13:40

2 Answers2

2

I was trying to implement this with the "Distance Matrix API" and this node package saved my life: https://www.npmjs.com/package/measuretool-googlemaps-v3

You just have to install it with:

npm i measuretool-googlemaps-v3

Include the MeasureTool.min.js file in your code.

And create a new measure tool object for the google.maps.Map instance:

measureTool = new MeasureTool(map, {
  showSegmentLength: true,
  tooltip: true,
  unit: MeasureTool.UnitTypeId.METRIC // metric, imperial, or nautical
});

Then you will be able to right-click and have the same functionality that google maps have.

Live Demo

Jon Kern
  • 3,186
  • 32
  • 34
MrMojoRisin
  • 1,349
  • 1
  • 12
  • 9
1

I don't know all of their APIs but this one can compute a distance matrix.

https://developers.google.com/maps/documentation/distancematrix/

Otherwise you can see this answer:

Calculate distance between two points in google maps V3

Community
  • 1
  • 1
Harold Ship
  • 989
  • 1
  • 8
  • 14
  • Thanks, I had looked at those and I've found other rulers, I'm specifically looking to see if there was a way to get the google maps 'measure distance' feature into the maps api. I've found other rulers, but want that one specifically. This is the one I'm referring to: http://mashable.com/2014/07/09/google-maps-measure-distances/ – Mark Reimer Mar 20 '15 at 19:23
  • Hi, @MarkReimer finally did you find a way to achieve it? – Juan Camilo Mejia Apr 21 '16 at 14:07