Possible to add an overlay on a map using MapKit? - iphone

Is it possible to add an overlay image on top of a map added in my app? I am using MapKit to show the map of an area. I would like to add an overlay image on top of the map before the pins show up
i.e. the stack should be map->image overlay->pins
Is it possible without going into the hierarchy of views - get all subviews of the view and then add an image just on top of the map?
Thanks.

I know that you need a solution for a static map , but here's one for a "draggable" one , which should also solve your problem.
You should subclass MKOverlayView , and override its (empty by default):
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context.
The method should actually do what drawRect does in views.
You should also implement another "should" method , that should return TRUE if the overlay should be visible on screen (in your case.. always ?).
In the overriden method , you should draw your image on top of the map (according to the mapRect and zoomScale of course) , and viola!
Some more reference :
http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html#//apple_ref/doc/uid/TP40009497-CH6-SW15

Try taking a look into the MKOverlayView outlined in the MKMapView documentation (see link). In addition, it may be worth reviewing "Apple WWDC Session 127 - Customizing Maps with Overlays".

If you watch that "Apple WWDC Session 127 - Customizing Maps with Overlays" session there is a part about about raster images as overlays. If you download the 2010 WWDC Sample Code there is an example named "TileMap" which has the code for doing that.

Related

MapKit with custom Maps

For my next project I have an image of a small village and I have to turn this into a map.
In this map I have to be able to add MKAnnotationView like the "normal" MapKit Map. The user can also zoom the map. I'm just trying to figure out how to implement this custom map: The only possible way is to create a UIImageView as subviews to which I add the "reproductions" of MKAnnotationView?
Any suggestions on how I can create this type of map?
Also have a look at MapBox. There are two options:
MapBox iOS SDK - works like MapKit, but is an open source alternative that lets you do completely custom maps (iOS 5+).
MBXMapKit - built on MapKit, but allows custom map tiles (iOS 7+).
I don't think using a UIImageView will work particularly well. If the suggested source code doesn't work for you, look at the documentation and sample code for CATiledLayer.

How to drop a pin on the map on a particular place And draw route from user current location to that praticular place?

IN my project I need to draw a route between two pins. Can anyone tell me what are the methods used. And give me the example code for that.
Try these posts.. It will help you i think
http://navarra.ca/?p=786
http://spitzkoff.com/craig/?p=108
This will automatically use Google Direction API and will fetch the points in between the locations i guess..
Anyhow see this blog http://laurilarjo.wordpress.com/2010/10/23/using-google-directions-api-and-drawing-routes-in-iphone-mkmapview/
You can use MKPolyLineView - it allows you to draw a line (or polyline, if you need several segments) as an overlay on top of the MKMapView. Apple even has example code using this here.
Note that this method uses an MKOverlayView which was added in iOS 4, so it only works in iOS 4+. If you need to target iOS 3 devices, then you can use the MKAnnotationView hack that others have linked to (originating as far as I can tell from that spitzkoff blog post). I used to do it that way, but did away with it when iOS 4 had matured enough - I'd wholeheartedly recommend doing it the new way if you don't need iOS 3 support.
As for pins, use MKPinAnnotationView
Go to google maps. "Get directions". Make a screenshot. Then use UIImageView. This is what I would do.

Custom camera zoom functionality on iPhone

I am new to XCode. I am trying to develop a custom camera with an overlay view . I am able to load this well and it's working great.
Now I want to add zoom functionality activated with a button on the overlay view.
Can any one guide me? I'm trying to find out how to zoom the camera, but I haven not bene able to find anything.
Thank you
You can use cameraViewTransform property :
cameraViewTransform The transform to
apply to the camera’s preview image.
#property(nonatomic) CGAffineTransform
cameraViewTransform Discussion This
transform affects the live preview
image only and does not affect your
custom overlay view or the default
image picker controls. You can use
this property in conjunction with
custom controls to implement your own
electronic zoom behaviors.
You can access this property only when
the source type of the image picker is
set to
UIImagePickerControllerSourceTypeCamera.
Attempting to access this property for
other source types results in the
throwing of an
NSInvalidArgumentException exception.
Availability Available in iOS 3.1 and
later. Declared In
UIImagePickerController.h
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html

Resizing Custom MKAnnotationView According to MapKit Zoom Level

Here is the situation:
I am displaying images on the map by using custom annotations. Everything works fine but I would like to improve it visually by resizing the AnnotationView so that it shrinks as the map is zoomed out. I want to do this because, obviously, more annotations fill up the screen and need to be shrunk so that they don't overlap each other too much and the user can see more annotations. (Of course, I would like to enlarge AnnotationViews when the map is zoomed in again).
I have achieved this by removing all annotations from the map and adding them back again, whenever regionDidChangeAnimated is called. However, these images are loaded from the internet, so downloading the images again (since the annotations have been removed) doesn't seem to make sense.
I hope I have explained the situation well, and hope to contribute to SO in the future.
Thanks in advance.
P.S. I'm developing with iOS 4.0
Since you are using iOS 4.0 I would suggest using a class that conforms to the MKOverlay protocol instead of MKAnnotationView. Overlays zoom with the map and will scale appropriately. You can probably use 1 overlay to handle all your annotations. Check out the HazardMap demo Apple provided in the 2010 WWDC talks on http://developer.apple.com
Alternatively, you could use something like the k nearest neighbors algorithm to group annotations per zoom scale. However, that can be kind of slow if you have a lot of annotations. I tried it once with several thousand annotations and did not like the performance hit that was incurred. I think < 1000 annotations might have decent performance with this method though.
It sounds like you're already on the right path and that the only real problem is the downloading of the images. Is there any particular reason you can't cache them by writing them to the documents directory (or the cache directory if you want them to go way when the app quits) when you receive them and look there first before displaying them?

How can I use MKPinAnnotationView on top of a regular UIView (instead of on a map)

I'm writing an iPhone application that will contain a custom map -- my own image for the map, not Google's. The image isn't very large, so instead of using a library such as RouteMe, I'm opting for just a UIScrollView with an embedded image (the map).
My question is: it is possible to re-use Apple's MKPinAnnotationView classes on top of my custom UIView so that the pin interactions will feel the same as MapKit? I have so far figured out how to add a pin to my map and position it, but I can't figure out how to let the user interact with it -- i.e. make the description bubble pop up.
Any thoughts? Thanks very much.
You might be able to make one and use add subview in order to display it, ull prolly have to do some work to get it to display where u want it to since the coordinates u give are meant to work eith mkmaps
Have you looked at this method from MKAnnotationView:
(void)setSelected:(BOOL)selected animated:(BOOL)animated
It's the only method that is publicly exposed that may show/hide the callout bubble. Other than that, you'd have to reverse engineer the classes and start poking around.
However, I would highly recommend against reverse engineering the classes and using methods that aren't publicly exposed. Apple makes no promises on maintaining backwards compatibility and if they figure out that you are using private methods, they'll kick your app from the store.
btw, full disclosure, these are Apple's documentation notes for setSelected:animated:
Discussion
You should not call this method
directly. An MKMapView object calls
this method in response to user
interactions with the annotation.