How to detect if a point is in a Circle?

前端 未结 6 774
广开言路
广开言路 2020-12-02 00:26

How can I test if a LatLng point is within the bounds of a circle? (Google Maps JavaScript v3)

The getBounds() method returns the bounding box for the circle, which

6条回答
  •  半阙折子戏
    2020-12-02 01:07

    Why don't you simple calculate this with Pythagorean theorem? You know a²+b²=c². If c is lower than r (radius) you know it is inside.

    var isInside=Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2) >= r*r;
    

提交回复
热议问题