地图:在矩形内是lat / lgn [英] Maps: is lat/lgn inside a rectangle

查看:190
本文介绍了地图:在矩形内是lat / lgn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设一个由西南纬度/经度(a,b)和纬度经度纬度/纬度(c,d)坐标定义的矩形:

  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屋!

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