Skip to content

Getting Radius #1962

Answered by joobacca
Diliru96 asked this question in Q&A
Jan 19, 2021 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

You can get the bounds of the map instance using map.getBounds(), and then use this function/formula:

function getBoundsRadius(bounds) {
  // r = radius of the earth in km
  const r = 6378.8;
  // degrees to radians (divide by 57.2958)
  const neLat = bounds.getNorthEast().lat() / 57.2958;
  const neLng = bounds.getNorthEast().lng() / 57.2958;
  const cLat = bounds.getCenter().lat() / 57.2958;
  const cLng = bounds.getCenter().lng() / 57.2958;
  // distance = circle radius from center to Northeast corner of bounds
  const radius =
    r *
    Math.acos(
      Math.sin(cLat) * Math.sin(neLat) +
        Math.cos(cLat) * Math.cos(neLat) * Math.cos(neLng - cLng),
    );
  return radius; // ra…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@Diliru96
Comment options

Answer selected by Diliru96
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants