Google Map V3 JavaScript calculates the distance between two marker
To do map development, the most commonly used is to marker some operations and interaction. Briefly, the distance between two marker is calculated.
Google Map API is very convenient as long as the commonly used are basically interfaces.
1. Create two marker points
Copy Code code as follows:
var oldmarker = new Google.maps.Marker ({
Position:new google.maps.LatLng ("31.95678", "177.898673"),
Map:map,
Title: "Old"
});
var newmarker = new Google.maps.Marker ({
Position:new google.maps.LatLng ("31.45678", "177.098673"),
Map:map,
Title: "New"
});
2. Loading Geometry library
Copy Code code as follows:
<script type= "Text/javascript" src= "http://maps.googleapis.com/maps/api/js?sensor=false&libraries= Geometry "></script>
Description: Libraries=geometry
3. Calculate the distance
Copy Code code as follows:
var meters = Google.maps.geometry.spherical.computeDistanceBetween (Oldmarker.getposition (), Newmarker.getposition ( ));
document.getElementById ("Distance"). innertext = meters+ "M";
Description: Unit is M
Oldmarker.getposition () Gets the current position of the Oldmarker (latitude and longitude)