xcode - Trying to Center Map on Pin (MKMapView) -
struggling find way create map zoom , center on annotation pin. pin drops, map loads ocean. code below.
- (void) connectiondidfinishloading:(nsurlconnection *)connection { [self setstring]; nsdictionary *dic = [nsjsonserialization jsonobjectwithdata:responsedata options:0 error:nil]; nsdictionary *location = [dic objectforkey:@"location"]; nsdictionary *coordinate = [location objectforkey:@"coordinate"]; nsstring *lat = [coordinate objectforkey:@"latitude"]; nsstring *lon = [coordinate objectforkey:@"longitude"]; (nsdictionary *diction in coordinate) { [array addobject:lat]; [array addobject:lon]; } { cllocationcoordinate2d track; track.latitude = [lat doublevalue]; track.longitude = [lon doublevalue]; mapviewannotation *newannotation = [[mapviewannotation alloc] initwithtitle:@"title of place here" andcoordinate:track]; [self.mapview addannotation:newannotation]; } }
2nd question, related:
after implementing reply above question, have since modified code. now, have coordinates coming mkmapview previous view, don't have bother making api phone call twice, sec beingness in mkmapview. in viewwillappear have following, , 1 time again experiencing problem view not center , zoom on pin:
if ([self.stringtodisplay isequaltostring: @"firehouse gallery"]) { uiimage *img = [uiimage imagenamed:@"firehouse.jpg"]; [imageview setimage:img]; cllocationcoordinate2d track; track.latitude = [lat doublevalue]; track.longitude = [lon doublevalue]; mkcoordinateregion region; mkcoordinatespan span; span.latitudedelta = 0.01; span.longitudedelta = 0.01; region.span = span; region.center = track; mapviewannotation *newannotation = [[mapviewannotation alloc] initwithtitle:@"firehouse gallery" andcoordinate:track]; [self.mapview addannotation:newannotation]; [self.mapview setregion:region animated:true]; [self.mapview regionthatfits:region]; }
feedback appreciated, can't tell else should do. pin loads on right coordinates, doesn't center/zoom...
try this:
{ cllocationcoordinate2d track; track.latitude = [lat doublevalue]; track.longitude = [lon doublevalue]; mkcoordinateregion region; mkcoordinatespan span; span.latitudedelta = 0.01; span.longitudedelta = 0.01; region.span = span; region.center = track; mapviewannotation *newannotation = [[mapviewannotation alloc] initwithtitle:@"title of place here" andcoordinate:track]; [self.mapview addannotation:newannotation]; [self.mapview setregion:region animated:true]; [self.mapview regionthatfits:region]; }
xcode xcode4 annotations mkmapview
No comments:
Post a Comment