mapkit - Multiple pin drop on map in iphone aap -
i doing code multiple pin drop on mapview.
- (void)geocode { nsarray *arrcityname = [nsarray arraywithobjects:@"baroda", @"surat", @"ahmedabad", @"rajkot", @"junagadh", @"mumbai", @"mehsana", @"veraval", @"surendranagar", @"gondal", nil]; cllocationcoordinate2d coordinate; mkcoordinateregion region; displaymap *ann = [[displaymap alloc] init]; [_mapview setmaptype:mkmaptypestandard]; [_mapview setzoomenabled:yes]; [_mapview setscrollenabled:yes]; [_mapview setdelegate:self]; (int = 0; < [arrcityname count]; i++) { coordinate = [self geocodeusingaddress:[arrcityname objectatindex:i]]; nslog(@"lat: %f --- long: %f --- city:--> %@",coordinate.latitude,coordinate.longitude,[arrcityname objectatindex:i]); region.center.latitude = latitude; region.center.longitude = longitude; region.span.longitudedelta = 1.8; region.span.latitudedelta = 1.8; [_mapview setregion:region animated:yes]; ann.title = [arrcityname objectatindex:i]; ann.coordinate = region.center; [_mapview addannotation:ann]; } } - (cllocationcoordinate2d) geocodeusingaddress:(nsstring *)address { latitude = 0, longitude = 0; nsstring *esc_addr = [address stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]; nsstring *req = [nsstring stringwithformat:@"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%@", esc_addr]; nsstring *result = [nsstring stringwithcontentsofurl:[nsurl urlwithstring:req] encoding:nsutf8stringencoding error:null]; if (result) { nsscanner *scanner = [nsscanner scannerwithstring:result]; if ([scanner scanuptostring:@"\"lat\" :" intostring:nil] && [scanner scanstring:@"\"lat\" :" intostring:nil]) { [scanner scandouble:&latitude]; if ([scanner scanuptostring:@"\"lng\" :" intostring:nil] && [scanner scanstring:@"\"lng\" :" intostring:nil]) { [scanner scandouble:&longitude]; } } } cllocationcoordinate2d center; center.latitude = latitude; center.longitude = longitude; return center; }
here issue giving last pin drop. want multiple pin drop per array value.
i facing similar issue when tried add multiple pins. did : set global counter increase 1 on every annotation added i.e. on addannotaion. create function of loop :
coordinate = [self geocodeusingaddress:[arrcityname objectatindex:i]]; nslog(@"lat: %f --- long: %f --- city:--> %@",coordinate.latitude,coordinate.longitude,[arrcityname objectatindex:i]); region.center.latitude = latitude; region.center.longitude = longitude; region.span.longitudedelta = 1.8; region.span.latitudedelta = 1.8; [_mapview setregion:region animated:yes]; ann.title = [arrcityname objectatindex:i]; ann.coordinate = region.center; [_mapview addannotation:ann];
and call function till count reaches arrcityname's count
- (mkannotationview *)mapview:(mkmapview *)mapview viewforannotation:(id <mkannotation>)annotation { static nsstring *identifier = @"carlocation"; if ([annotation iskindofclass:[mapviewannotation class]]) { static nsstring *annotationidentifier = @"annotationidentifier"; mkpinannotationview *pinview = (mkpinannotationview *)[mapview dequeuereusableannotationviewwithidentifier:annotationidentifier]; if (!pinview) { pinview = [[[mkpinannotationview alloc] initwithannotation:annotation reuseidentifier:annotationidentifier] autorelease]; pinview.canshowcallout = yes; pinview.animatesdrop = yes; } else { pinview.annotation = annotation; } uiimageview *leftcalloutview = [[uiimageview alloc] initwithimage:((mapviewannotation *)annotation).imagepin]; pinview.leftcalloutaccessoryview = leftcalloutview; pinview.image = leftcalloutview.image; [leftcalloutview release]; [self performselector:@selector(intermediate) withobject:nil afterdelay:1.05]; return pinview; }
Comments
Post a Comment