1

I am trying to add Google maps in Salesforce - Apex code; did so successfully. I also have 2 markers on the map. But now I want to find the distance between these 2 markers. Can anybody please help me to find the distance between the 2 markers in Google maps.

Please explain me how.

Thanks

Anuraj

dda
  • 6,030
  • 2
  • 25
  • 34
AnuRaj
  • 27
  • 2
  • 6

1 Answers1

3

There's a quick way using the geometry library. First, load it when adding the API (since it's optional)

<script type="text/javascript" 
  src="http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false">
</script>

Then call the measuring function:

meters = google.maps.geometry.spherical.computeDistanceBetween(
           markerA.getPosition(), markerB.getPosition());

(or enter LatLngs instead). The result is in meters.

Tina CG Hoehr
  • 6,721
  • 6
  • 44
  • 57
  • thanks for you help. Can you please help me how to display it on an HTML page? – AnuRaj May 30 '12 at 09:27
  • You can edit your question with Your HTML and then I'll see where this calculation should go. – Tina CG Hoehr May 30 '12 at 21:48
  • can you tell me how can i display it any where. Just want to know what is the result coming i am not able to see the result. I asked you this because i want to make simple for you. – AnuRaj May 31 '12 at 12:08
  • The result is in the variable meters in the example above. I wrote a demo so you can see the result distance between 2 markers. http://jsfiddle.net/nbCAy/1/ – Tina CG Hoehr May 31 '12 at 22:22