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

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

Related

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).

Tile Overlays in iPhone App

There is a webpage I am looking at that displays a Google Map (via javascript), but certain areas of the map have an overlay (textures appear different than the rest of the map, etc.). From what I can gather, this is done on the webpage via a getTileURL function, which depends on the zoom level and current coordinate.
I am interested in portraying this same overlay in my iPhone application, which currently has a mapView set up. Is there anyway to implement the same sort of getTile function in objective-c for a mapView?
If someone could please provide some sample code or point me in the right direction I would greatly appreciate it. Thank you.

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.