L.Geometryutil.Distance – Calculate Distance To Linestring

How to calculate a new point (marker B) at a given distance in meter from a marker A and at a given angle in degree?

Google API has this but I can”t find it in Leaflet:

var pointA = new google.maps.LatLng(25.48, -71.26); var radiusInKm = 10;var pointB = pointA.destinationPoint(90, radiusInKm);


Đang xem: L.geometryutil.distance



You can use the destination method of Leaflet.GeometryUtil to calculate the destination point and create a marker there :

var center = <40.69, -73.98>;var radiusInKm = 10;var angleInDegrees = 90;var A = L.marker(center).addTo(map);var B = L.GeometryUtil.destination(markerA.getLatLng(), angleInDegrees, radiusInKm * 1000);L.marker(B).addTo(map);and a demo

var center = <40.69,-73.98>;var radiusInKm = 10;var angleInDegrees = 90;var map = L.map(“map”).setView(center, 11);L.tileLayer(“http://{s}.tile.osm.org/{z}/{x}/{y}.png”, { attribution: “© OpenStreetMap contributors”}).addTo(map);var marker = L.marker(center).addTo(map);L.circle(marker.getLatLng(), { color: “red”, fillColor: “#f03”, fillOpacity: 0.2, radius: radiusInKm * 1000}).addTo(map);var to = L.GeometryUtil.destination(marker.getLatLng(), angleInDegrees, radiusInKm * 1000);L.marker(to).addTo(map);html, body { height: 100%; margin: 0;}#map { width: 100%; height: 100%;}

If you want to avoid an external library, you can take inspiration from the destination method source code (currently at line 712).


Xem thêm: X Derivative Factorial (X!)?: Math Factorial: Differentiation


Thanks for contributing an answer to Stack Overflow!

Please be sure to answer the question. Provide details and share your research!

But avoid

Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

See also  Controll In Geometry A Solid May Exist In A Plane True Or False?

Post Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged javascript leaflet or ask your own question.


Xem thêm: Proverbs Ministries – Proverbs 31 Ministries

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.8.10.39952

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

See more articles in category: Geometry

Leave a Reply

Back to top button