如何确定当前用户位置是否在我的MKCoordinateRegion内? [英] How do I determine if the current user location is inside of my MKCoordinateRegion?

查看:216
本文介绍了如何确定当前用户位置是否在我的MKCoordinateRegion内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我已经确定的坐标区域包含了我想要为我的应用展示的限制。我已经把它设置为一个带有中心点纬度,经度和跨度的MK坐标区域。如何确定当前的userLocation是否位于我的坐标区域内? 使用map rects。使用map rects。以下是使用地图当前可见矩形的示例。关于您的问题,您可以使用 convertRegion:toRectToView:先将您的区域预先转换为 MKMapRect

  MKMapPoint userPoint = MKMapPointForCoordinate(mapView.userLocation.location.coordinate); 
MKMapRect mapRect = mapView.visibleMapRect;
BOOL inside = MKMapRectContainsPoint(mapRect,userPoint);


I have a coordinate region that I have determined contains the limits of what I want to show for my app. I have set this up as an MKCoordinateRegion with center point lat, longitude and a span. How do I determine if the current userLocation is inside of my coordinate region?

解决方案

Use map rects. Here's an example using the map's current visible rect. With regards to your question, you could use convertRegion:toRectToView: to first convert your region to a MKMapRect beforehand.

MKMapPoint userPoint = MKMapPointForCoordinate(mapView.userLocation.location.coordinate);
MKMapRect mapRect = mapView.visibleMapRect;
BOOL inside = MKMapRectContainsPoint(mapRect, userPoint);

这篇关于如何确定当前用户位置是否在我的MKCoordinateRegion内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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