Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine if the current user location is inside of my MKCoordinateRegion?

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?

like image 823
Alan Moore Avatar asked Feb 01 '12 04:02

Alan Moore


People also ask

How do I determine a user's location in a web browser?

To determine a user’s location in a web browser you can use the HTML Geolocation API. There are however a couple of issues with this. First, the user will be prompted to give permission for you to determine their location. If they deny this request, then you will not be able to determine the location.

What is the best way to detect a user's location?

Some browsers use IP addresses to detect a user's location. However, it may only provide a rough estimate of a user's location. The W3C approach is the easiest and most fully-supported so it should be prioritized over other geolocation methods.

How do I get the user's current location using the API?

The Geolocation API offers a simple, "one-shot" method to obtain the user's location: getCurrentPosition (). A call to this method asynchronously reports on the user's current location. If this is the first time that an application on this domain has requested permissions, the browser typically checks for user consent.

What can I do with the user's location data?

Tailor information (such as news) to the user's location. Show the position of a user on a map. Tag data created inside your application with the user's location (that is, geo-tag a picture). Recent user studies have shown that users are distrustful of sites that simply prompt the user to give away their position on page load.


1 Answers

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);
like image 108
firstresponder Avatar answered Oct 04 '22 14:10

firstresponder