Domanda

I need some help because the addAnnotations not work with following code:

NSString *postString = [[NSString alloc]initWithFormat:@"MM_act=%@",@"test"];
NSData *returnData = [requestURLData:@"location.php" postString:postString];
NSString *result = [[NSString alloc]initWithData:returnData encoding:NSUTF8StringEncoding];
//return JSON
if (![result isEqualToString:@""]) {
    NSMutableArray *ann_array = [[NSMutableArray alloc] init];
    NSError *error = nil;
    id object = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:&error];
    if ([object isKindOfClass:[NSDictionary class]]) {
        NSDictionary *jsonDictF = object;
        NSArray *arrayId = [jsonDictF objectForKey:@"Id"];
        NSArray *arrayLati = [jsonDictF objectForKey:@"Latitude"];
        NSArray *arrayLong = [jsonDictF objectForKey:@"Longitude"];
        for (int i=0; i<[arrayId count]; i++) {
            CLLocationCoordinate2D currentLocation = CLLocationCoordinate2DMake([[[NSString alloc] initWithFormat:@"%@",[arrayLati objectAtIndex:i]] floatValue], [[[NSString alloc] initWithFormat:@"%@",[arrayLong objectAtIndex:i]] floatValue]);
            NSString *ID = [[NSString alloc] initWithFormat:@"%@",[arrayId objectAtIndex:i]];
            MyAnnotation *annotation = [[MyAnnotation alloc] initWithCoordinate:currentLocation Title:@"test" AndSubtitle:@"" annIdentifier:ID];
            [ann_array addObject:annotation];
        }
        [m_mapView addAnnotations:ann_array];
    }
}

But I can see the annotation data in debug area,what's wrong? Please help me.

È stato utile?

Soluzione

Are you sure the location you're setting is in the currently visible region of the map? Did you scroll around and look to see if it was added?

Simply adding an annotation to a map does not zoom in on that annotation. You can use the following to zoom in on the newly added annotation:

-(void)zoomInOnLocation:(CLLocationCoordinate2D)location
{
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location, 200, 200);
    [self.map setRegion:[self.map regionThatFits:region] animated:YES];
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top