How to detect if a point is in a Circle?

前端 未结 6 764
广开言路
广开言路 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:10

    Use the spherical geometry library (be sure to include it with the API)

    function pointInCircle(point, radius, center)
    {
        return (google.maps.geometry.spherical.computeDistanceBetween(point, center) <= radius)
    }
    

提交回复
热议问题