如何检测一个点是否在Circle中? [英] How to detect if a point is in a Circle?

查看:111
本文介绍了如何检测一个点是否在Circle中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何测试LatLng点是否在圆的范围内? (Google Maps JavaScript v3)

getBounds()方法返回矩形的圆的边界框,所以如果一个点落在圆的外面,您可能会收到错误的答案。

解决方案

使用球形几何图形库(一定要将其包含在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)
}

这篇关于如何检测一个点是否在Circle中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆