Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding the measure distance feature to google maps api

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!

like image 714
Mark Reimer Avatar asked Oct 29 '25 14:10

Mark Reimer


2 Answers

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

like image 199
MrMojoRisin Avatar answered Oct 31 '25 11:10

MrMojoRisin


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

like image 34
Harold Ship Avatar answered Oct 31 '25 10:10

Harold Ship