-1

I made some 2 markers in google maps,i just want to ask how can i get the distance of the 2markers?

i have problem in my code it say

TypeError: google.maps.geometry is undefined

here is my code

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


    function initialize(){

        var map = google.maps.geometry.spherical.computeDistanceBetween( 10.185699,123.826437,10.254526,123.825959 );

        alert(map);


    }

    google.maps.event.addDomListener(window, 'load', initialize);

</script>
mathiascolebar
  • 199
  • 3
  • 10
  • Possible duplicate. Look [here](http://stackoverflow.com/questions/1502590/calculate-distance-between-two-points-in-google-maps-v3) – Andre Lombaard Sep 09 '13 at 15:46
  • What distance are you looking for? The straight line distance (use the geometry library) or the driving/walking/etc distance (use the DisrectionsService) – geocodezip Sep 09 '13 at 16:52
  • @geocodezip,I already posted my code can you please check why i got that error.Thank you. – mathiascolebar Sep 09 '13 at 16:55

1 Answers1

1

yes if you know the latitude and longitude co-ordinates of both of the markers. you could use these to figure out the the distance horizontally and vertically between the two markers and then use trigonometry to find the direct distance between the two of them.

There is a method already built into google maps however which may make your life easier, so long as you know the two markers latlng co-ords use this method:

google.maps.geometry.spherical.computeDistanceBetween (latLngA, latLngB);

Where latlng A and B represent your two markers.

This is probabally the easiest way to do it.

user2682570
  • 94
  • 1
  • 2
  • 10