Check if a latitude and longitude is within a circle google maps

前端 未结 3 2105
灰色年华
灰色年华 2020-12-08 03:26

Below is the desired result, which I\'m looking for

\"enter

<

3条回答
  •  佛祖请我去吃肉
    2020-12-08 03:47

    All you need is a little spherical trig

    First you need the central angle theta of the arc subtended by your distance (L = 10 km).

    L = theta*r
    

    where r is the radius of the earth (6378.135 km)

    Now, if the central angle between the point of interest and your center point is < theta, it is inside your circle. Call this angle theta_p.

    Here's a diagram illustrating a spherical triangle: spherical triangle image http://en.wikipedia.org/wiki/File:Spherical_trigonometry_basic_triangle.svg

    edit - sorry, apparently I don't know how to link to an image?? Here's the URL: http://en.wikipedia.org/wiki/File:Spherical_trigonometry_basic_triangle.svg

    In this case, two of the sides of the spherical triangle (call them a, b) are the difference in longitude and difference in latitude of the points respectively. The included angle C is 90 degrees (angle between lines of longitude and lines of latitude.

    The spherical trig law of cosines is:

    cos(c) = cos(a)*cos(b) + sin(a)*sin(b)*cos(C)
    

    c is the central angle between your points, which we earlier called theta_p

    edit - this solution isn't limited to small distance WRT the radius of the earth, as the other suggestions are.

提交回复
热议问题