I'm using MKMapView
and I send my php program the visible region (center lat, center lon, span lat, span lon). I need to determine if a coordinate is inside that region using php. I'm hoping there's a standard formula somewhere, but I haven't found one. I'll keep trying to come up with a formula, but it's surprisingly complicated (hopefully not as much as the haversine, which I don't believe I could have figured out myself).
确定坐标是否在区域内(MKMapView,用PHP解决)
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
4条回答 默认 最新
- dongyunqin7307 2015-06-24 03:47关注
My Solution
$top = $c_lat + ($d_lat / 2.0); $bottom = $c_lat - ($d_lat / 2.0); $left = $c_lon - ($d_lon / 2.0); $right = $c_lon + ($d_lon / 2.0); if($left < -180) { $second_left = $left + 360.0; $second_right = 180.0; $left = -180; } elseif($right > 180) { $second_right = $right - 360.0; $second_left = -180.0; $right = 180.0; } $inside = false; if($t_lat > $bottom && $t_lat < $top && $t_lon > $left && $t_lon < $right) $inside = true; else if($second_right && $second_left) { if($t_lat > $bottom && $t_lat < $top && $t_lon > $second_left && $t_lon < $second_right) $inside = true; } if($inside) { }
This seems to work with
MKMapView
since the region latitudes are always between -90 and 90.本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 #MATLAB仿真#车辆换道路径规划
- ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
- ¥15 数据可视化Python
- ¥15 要给毕业设计添加扫码登录的功能!!有偿
- ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
- ¥15 微信公众号自制会员卡没有收款渠道啊
- ¥100 Jenkins自动化部署—悬赏100元
- ¥15 关于#python#的问题:求帮写python代码
- ¥20 MATLAB画图图形出现上下震荡的线条
- ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘