且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检测一个点是否在Circle中?

更新时间:2023-11-29 16:53:35

使用球形几何图形库(一定要将其包含在API中)

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


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 is a rectangle, so if a point falls outside the circle but within the bounding box, you'll get the wrong answer.

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)
}