How to check user is located in between the coordinates, MKMapview - iphone

I had userlocation and a boundary.
And the boundary has 8 oordinates.
I need to check wether the user is in the boundary or not.
Am using mapview in iPhone.
Thanks in advance.

A way to do this using some built-in functions in Map Kit are to add your boundary as an MKPolygon overlay to the map view. Keep a reference to the overlay as an ivar.
Then whenever you want to check if user is inside the boundary (for example when user's location changes), convert the user coordinates to a CGPoint and retrieve the CGPath for the boundary and call CGPathContainsPoint. There are Map Kit functions to do these conversions.
This previous answer of mine gives an example of how to add an MKPolygon overlay and this one has an example of the CGPathContainsPoint part.

You can use the Point Inclusion in Polygon Test to check whether the users location is inside or outside the boundary (polygon).

Related

how to get current location as i slide the MapView?

I am using CLLocationManager to retrieve current location in my app and display using MapView, i want to slide the map so that the current location should also change to the new location where the map slides and it should annotate to the new location, how to do it? Please give your suggestions with sample code.
You probably don't mean "the current" since that means where the phone actually is, unless you want to transport the phone to another place when using this app which would be quite a feat. So, how about drawing a layer over the top of your map that keeps a pin drawn at the centre so it looks as if the pin is moving over the map, but really the map is moving under the pin.

How to draw a line on MKMapView showing the route a user has taken?

I have had a look around online to try and find out the best way to draw a line showing the route a user has travelled. I think I need to use the MKOverlayView, and I guess I need to collect a selection of data points to plot (would these be GPS coordinates?). The question I have is based on how I would draw the line and keep adding to it as the users location updates?
I also want to be able to clear the line when a user presses a button. How would I implement this (not the button press, just the code to clear the line off the map view)?
Thanks in advance!
You can do this using MKPolyline. At First you need to get coordinates of route, then draw polylines over it. You will find an example here to draw polyline over some coordinates.

How to add overlays designed by user on button click in a map

I am interested in adding an option to my GIS Map application, the ability to draw Polygon, circle, polyroutes overlays for the user to search data within.The problem is that I've read and tested codes of how to draw an overlay, but they are always static.I want it to be dynamic, with dynamic center and points (or radius) set by the user on click.A mystery for me.(I'm a beginner in iPhone programming, this is my first app.)And I'm not using and don't want to use things like ArcGIS API for iPhone.I would appreciate any help.
To let the user "draw" an arbitrary polygon on the map, one approach is to use draggable annotations that represent the corners of the polygon. Provide an "Add Corner" button and some kind of Remove Corner button on each annotation.
See my answer to User creating a box on MKMapView for some more details. On that question though, the OP actually ended up using another solution described in the comments which would work well if the polygons are always rectangles.
For implementing a button in an annotation view (if you want a "Remove Corner" button on the annotations), see my answer to How to get click event from a button added over MKAnnotationView.
Once you a have a polygon or other overlay on the map, dragging it by direct touches may only be possible by adding a gesture recognizer to the map (with its own scrolling turned off) and using a custom MKOverlay and MKOverlayView that allow coordinate changes. Adding a gesture recognizer directly to an MKOverlayView doesn't seem to work and the built-in overlay classes don't allow changes to coordinates.
An alternative to moving by direct touches is putting some controls on the side (Up/Down/Left/Right/etc buttons) that modify the custom overlay.
The Apple sample app Breadcrumb gives an example of a custom overlay/view for a path. In WWDC 2010, the sample app LocationReminders gives an example of a custom overlay/view for a circle that can move and resize.
Finally, when you do a search for businesses, you could use the overlay's boundingMapRect (which is always a rectangle regardless of the overlay's shape) as the bounding box for the initial search and then check if the coordinate of each business found is in the overlay's actual shape using the answer to How to determine if an annotation is inside of MKPolygonView (iOS).

What is the difference between MKOverlay and MKAnnotation?

I am new to MKMapView. I implemented a mapView which is looking good. But i was planning to add points or custom image as point in MapView. I can implement it with the help of MKAnnotation, but when i read MKOverlay it was mentioned that Overlays are also annotations. So whats the difference between these two??
Thanks in advance,
aby
In a nutshell, MKAnnotation is based on a point (x,y). MKOverlay is based on an area, bounded by a rectangle.
An MKAnnotation is simply a point on the map, often represented with a red pin icon (you'll see these if you search for a location in Apple's Maps app on iOS), whereas an MKOverlay is another layer over the map to display extra information. A good example of this could be the traffic overlay displayed on the map in US regions to indicate the current level of traffic.
You'd want to use an MKAnnotation in situations where you need to show the user a specific point on a map, but if you want to display more information to them over a larger area, go with an MKOverlay.
Apple uses an MKOverlay to display shipping routes for boats in their WWDC video on the topic (Session 127 – Customizing Maps with Overlays). That would be a good place to learn the full difference between the two, and how to use overlays correctly.

drawing routes view in iphone

how can i draw routes on a map. This is easily solved though by placing a custom UIView over the map that acts as the map delegate but didn't how can i do this, and how to take a series of CLLocation coordinates and plot them on the map, regardless of the location the user pans to or how far they have zoomed in.Give some hint to solve this or give some sample code to do this
thanks in advance
In ios4 apple has made some nice additions for this. Look at mkoverlay protocol and mkoverlayview.
You'll find an example here
http://spitzkoff.com/craig/?p=136