ios - Add Overlay to Mapview -
i have been doing ios dev few months. have map view couple of annotations pinned , can show users current location.
i haven been trying read through docs implement simple overlay using set of cllocationcoordinate2d draw out line (simple static route). has been struggle
my mkoverlayrenderer method doesnt seem running @ all. if not mistaking shouldn't need mkmapviewdelegate. trying implement mkoverlay delegate , have "@synthesize boundingmaprect;".
here code trying implement overlay
- (void)drawlineroute { cllocationcoordinate2d purplepoints[2]; purplepoints[0] = cllocationcoordinate2dmake(28.541944, -81.382936); purplepoints[1] = cllocationcoordinate2dmake(28.538447, -81.383096); mkpolyline *purplepolyline = [mkpolyline polylinewithcoordinates:purplepoints count:2]; purplepolyline.title = @"citrus bowl connection"; [self.mapview addoverlay:purplepolyline]; } - (mkoverlayrenderer *)mapview:(mkmapview *)mapview viewforoverlay: (id<mkoverlay>)overlay { if([overlay iskindofclass:[mkpolyline class]]) { mkpolygonrenderer *polyrender = [[mkpolygonrenderer alloc] initwithoverlay:overlay]; polyrender.linewidth = 2; polyrender.strokecolor = ovopurple; return polyrender; } return nil; }
any or guidance appreciated. thank in advance.
there 2 different delegate methods:
mapview:rendererforoverlay:
, introduced in ios 7, , returnsmkoverlayrenderer
; ,mapview:viewforoverlay:
, deprecated in ios 7, returnsmkoverlayview
, notmkoverlayrenderer
.
it incorrect implement viewforoverlay
returns mkoverlayrenderer
.
bottom line, if need support ios versions prior ios 7, implement viewforoverlay
returns mkoverlayview
, not mkoverlayrenderer
. if don't need support ios versions prior 7, not implement viewforoverlay
@ all, rather implement rendererforoverlay
returns mkoverlayrenderer
.
Comments
Post a Comment