MKOverlayRenderer to display UIImage over map view

亡梦爱人 提交于 2019-12-06 01:14:12

There are a couple of problems:

  1. Where is the code actually adding an overlay to the map by calling addOverlay? You'll need to create an object of type id<MKOverlay> and pass it in the addOverlay call. You could create a custom class that implements MKOverlay but in this case, you could just use MKCircle to represent the position and size of your image. In the showSeattle: method:

    CLLocationCoordinate2D location = {47.61167908,-122.33325958};
    int radius = 100000; //radius in meters
    
    MKCircle *c = [MKCircle circleWithCenterCoordinate:location radius:radius];
    [self.mapView addOverlay:c];
    
    MKCoordinateRegion region = ...
    
  2. In rendererForOverlay, the code is creating an instance of MapOverlayRenderer but not giving it a reference to the underlying overlay model object. Call initWithOverlay instead:

    MapOverlayRenderer *mapOverlay 
        = [[MapOverlayRenderer alloc] initWithOverlay:overlay];
    


By the way, you could put an image at the location much more easily using an annotation (but the image won't scale with the zoom level as an overlay-based image will). Not sure which functionality you want.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!