地图:在矩形内是lat / lgn [英] Maps: is lat/lgn inside a rectangle
问题描述
c,d
| ----------- |
| |
| |
| |
| ----------- |
a,b
如何确定另一对坐标x,y是否在长方形?这是正确的:
a< x < c和b < y< d < - 如果为true,则表示x,y在矩形中?
我正在使用Google Maps API,并从中获取这些纬度/经度值。我只需要知道x,y是否确实在矩形内。
首先创建一个 LatLngBounds
来自西南和东北的coords,然后调用传入LatLng的方法来检查。
https://developers.google.com/maps/documentation/javascript / reference#LatLngBounds
Assume a rectangle defined by south-west lat/lgn (a,b) and north-east lat/lng (c,d) coordinates:
c,d
|-----------|
| |
| |
| |
|-----------|
a,b
How do I determine if another pair of coordinates x,y are within that rectangle? Is this correct:
a < x < c AND b < y < d <-- if true, it means x,y are in the rectangle???
I'm using Google Maps API and am getting these lat/lng values from it. I just need to know if x,y are indeed inside the rectangle.
解决方案 First create a LatLngBounds
from the southwest and northeast coords, then call the contains
method passing in the LatLng to check.
https://developers.google.com/maps/documentation/javascript/reference#LatLngBounds
这篇关于地图:在矩形内是lat / lgn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!