drawing routes view in iphone - 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

Related

OpenStreetMap/iOS: Markers and Routes Don't Work Together

I am a newbie to OpenStreetMap, but have a fair amount of iOS development experience. I'm working on an app that will have an OpenStreetMap map on it, with markers that respond to a touch, and a route generated programmatically from an array of locations. I can make all the pieces work, but together: not so good.
Following examples, I put the markers on the map, and hook the mapView to a delegate, so I can respond to touches on the markers. Then, again following examples, I create a CMRoute and add it as a sublayer ([mapView.contents.overlay addSublayer:walkRoute.path];). Doing that essentially hides the markers under the route sublayer; they no longer respond to a touch.
Can anyone point me in a direction that will give me the means to have a mapView and a route sublayer and still be able to detect marker touches? I don't ask for code (though that would be nice) but thoughts on how this could be accomplished.
Thanks

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.

moving a map overlay

I am trying to create an app where the user can mark an area on a map. I want him to be able to move the area he marked.
I found that there is an api for adding overlays on a map, but I cannot get to move those overlays once I put them on the map. I tried to subclass the MKCircleView with my own view and implement the touchesBegan:withEvent: method but it never seems to get called.
Any ideas how this can be implemented and why it doesn't work this way?
Thanks.
Try looking through the apple developer code for sample called Regions.
It has circles which can be dragged and moved around.

iPhone - MapKit - Searching locations and moving annotations

I want to make an app that partially mimics some of the behavior the standard map application has. This has proven difficult. First of all, I don't understand how you make annotations movable. How exactly do you do this?
Second: how do you search for locations?
Moving annotations
I'm assuming you're after the behavior of Maps.app where you tap and hold on to a pin to move it around freely. As far as I know, there is no built in way of moving annotations around. Since annotations are subclasses of UIView though, you can draw them where and how you'd like. You could for example detect a tap-n-hold on the annotation, and when "unlocked" change the centerOffset value of your annotation to move it around with the touch. When the user lets go of the the view, you can note the position on the screen, and use the MKMapView method convertPoint:toCoordinateFromView: to get the coordinates that the pin was released.
Search for location
What you are looking for is called Forward Geocoding. Unfortunately, MapKit only comes with Reverse Geocoding (the process of converting GPS coordinates to country/city/street/etc). There is, however, several alternatives. Here's a few ways:
http://code.google.com/apis/maps/documentation/geocoding/index.html
http://cloudmade.com/products/iphone-sdk
http://www.geonames.org/export/web-services.html
http://developer.yahoo.com/maps/rest/V1/geocode.html
Note that many geocoding APIs are licensed under Creative Commons, or similar licenses.
You should be able to get drag-and-drop annotations going with the help of this blog post. I used it to do the same thing, and it was pretty simple to get going.
MapKit annotation drag and drop with callout info update

MKMapView tile-based overlay

I want to draw a tile-based overlay on top of a MKMapView, but there's no obvious way to do this.
This appears to be tricky since you can zoom to any level with MKMapView (unlike Google Maps).
Has anyone attempted to do this?
Incase this question is still getting views readers should check out the HazardMap and TileMap demo code from WWDC2010.
I'm working on a game where I need to overlay objects on the map and have them scroll and zoom with the map.
Using annotation views I've been able to solve the first problem and partially solve the second problem. Annotations automatically move with the map. For scaling them, I use the mapView:regionDidChangeAnimated: delegate method to resize my annotations after a zoom event. The problem is that the annotations don't rescale until after the zoom gesture is complete.
I can think of two approaches other than filing a bug with Apple requesting that they provide an API for map overlays:
Put a (mostly invisible) view over the top of the MKMapView that intercepts zoom and scroll events, handles them, and passes them on to the map view.
Customize the open-source RouteMe library with tiles from Open Street Map or CloudMade (the former is slow, the latter costs money). But it's fully open source so you should be able to do overlays to your heart's content. You could also run your own tile server that does the tile overlays on the server.
Something I discovered later:
http://www.gisnotes.com/wordpress/2009/10/iphone-devnote-14-drawing-a-point-line-polygon-on-top-of-mkmapview/
Not quite a tile-based solution, but interesting nonetheless.