开发者

Possible to add an overlay on a map using MapKit?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜