我需要一些帮助,因为addAnnotations无法使用以下代码:
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];
}
}
但我可以在调试区看到注释数据,有什么问题? 请帮帮我。
答案 0 :(得分:2)
您确定所设置的位置是否位于地图当前可见的区域?您是否滚动并查看是否已添加?
简单地向地图添加注释不会放大该注释。 您可以使用以下内容放大新添加的注释:
-(void)zoomInOnLocation:(CLLocationCoordinate2D)location
{
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location, 200, 200);
[self.map setRegion:[self.map regionThatFits:region] animated:YES];
}