Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to set two different pin colors when populating mapview
    primarykey
    data
    text
    <p>I am parsing two json feeds. The first json feed parses pharmacies of a particular region and populates the mapview, the second feed parses a list of burger shops present in that region and populates the mapview. What I want is to set the pins representing the first feed in red color and the second feed in green color. I am a noob, could you help me out? Below is the code.</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; self.title=@"Map"; [self secondMap]; [self firstMap]; } -(void)secondMap { jsonurl1=[NSURL URLWithString:@"http://dev-parkguiden.knutpunkten.se/Api/GetPharmacyJson"]; NSURLRequest *request1 = [NSURLRequest requestWithURL:jsonurl1 cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; connection1=[[[NSURLConnection alloc] initWithRequest:request1 delegate:self] autorelease]; self.jsonData1=[[NSString alloc]initWithContentsOfURL:jsonurl1]; self.jsonArray1 = [self.jsonData1 objectFromJSONString]; NSLog(@"blah:%@",jsonArray1); items= [self.jsonArray1 objectForKey:@"pharmacies"]; NSDictionary *bam=[items valueForKey:@"location"]; for (NSDictionary *item in bam) { latitude=[[item valueForKey:@"latitude"] floatValue]; longitude=[[item valueForKey:@"longitude"] floatValue]; NSLog(@"String3:%f",latitude); NSLog(@"String4:%f",longitude); Place* home = [[[Place alloc] init] autorelease]; home.name = [item valueForKey:@"Name"]; // home.description=[item valueForKey:@"description"]; home.latitude = latitude; home.longitude = longitude; PlaceMark *from = [[[PlaceMark alloc] initWithPlace:home] autorelease]; [mapView addAnnotation:from]; NSLog(@"the latitude:%f",latitude); NSLog(@"the latitude:%f",longitude); [self centerMap]; } } -(void)firstMap { jsonurl=[NSURL URLWithString:@"http://dev-parkguiden.knutpunkten.se/Api/WhereIam?longitude=18.105469&amp;latitude=59.304786&amp;distance=100"]; NSURLRequest *request = [NSURLRequest requestWithURL:jsonurl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; connection1=[[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease]; //NSLog(@"jsonurl:%@",jsonurl); self.jsonData=[[NSString alloc]initWithContentsOfURL:jsonurl]; self.jsonArray = [self.jsonData objectFromJSONString]; NSLog(@"blah:%@",jsonArray); items = [self.jsonArray objectForKey:@"parks"]; story = [[NSMutableArray array]retain]; media1 = [[NSMutableArray array]retain]; url=[[NSMutableArray array]retain]; descriptiondesc=[[NSMutableArray array]retain]; for (NSDictionary *item in items ) { latitude=[[item valueForKey:@"latitude"] floatValue]; longitude=[[item valueForKey:@"longitude"] floatValue]; NSLog(@"String1:%f",latitude); NSLog(@"String2:%f",longitude); Place* home = [[[Place alloc] init] autorelease]; home.name = [item valueForKey:@"Name"]; // home.description=[item valueForKey:@"description"]; home.latitude = latitude; home.longitude = longitude; PlaceMark *from = [[[PlaceMark alloc] initWithPlace:home] autorelease]; [mapView addAnnotation:from]; NSLog(@"the latitude:%f",latitude); NSLog(@"the latitude:%f",longitude); [self centerMap]; } } -(void) centerMap { MKCoordinateRegion region; MKCoordinateSpan span; span.longitudeDelta=0.1; span.latitudeDelta=0.1; CLLocationCoordinate2D location=mapView.userLocation.coordinate; location.latitude=latitude; location.longitude=longitude; region.span=span; region.center=location; [mapView setRegion:region animated:TRUE]; [mapView regionThatFits:region]; } - (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id &lt;MKAnnotation&gt;)annotation { mapView.mapType=MKMapTypeHybrid; mapView.showsUserLocation=YES; MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"]; annView.pinColor = MKPinAnnotationColorGreen; annView.animatesDrop=TRUE; annView.canShowCallout = YES; annView.calloutOffset = CGPointMake(-5, 5); UIButton *detailButton=[UIButton buttonWithType:UIButtonTypeDetailDisclosure]; //NSInteger annotationValue=[self.annotations indexOfObject:annotation]; [detailButton addTarget:self action:@selector(showDetailView) forControlEvents:UIControlEventTouchUpInside]; annView.rightCalloutAccessoryView=detailButton; return annView; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload