Distance between two marker in Javascript computing (Google Map V3)

Source: Internet
Author: User

Google Map V3 javascript calculates the distance between two marker
For map development, some operations and interactions of marker are most commonly used. A brief introduction is the distance calculation between two marker.
Google map api is very convenient, as long as it is commonly used, there are basically interfaces.
1. Create two marker points Copy codeThe Code is 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. Load the geometry Database Copy codeThe Code is as follows: <script type = "text/javascript" src = "http://maps.googleapis.com/maps/api/js? Sensor = false & libraries = geometry "> </script>

Libr: libraries = geometry
3. Calculate the distance Copy codeThe Code is as follows: var meters = google. maps. geometry. spherical. computeDistanceBetween (oldMarker. getPosition (), newMarker. getPosition ());
Document. getElementById ("distance"). innerText = meters + "meter ";

Description: The unit is meters.
OldMarker. getPosition () gets the current location of oldmarker (longitude and latitude)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.