gpt4 book ai didi

ios - MKMapView addAnnotation 不起作用

转载 作者:行者123 更新时间:2023-11-28 22:15:46 27 4
gpt4 key购买 nike

我需要一些帮助,因为 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];
}
}

但是我在调​​试区可以看到注释数据,怎么了?请帮助我。

最佳答案

您确定您设置的位置在 map 的当前可见区域中吗?您是否滚动查看它是否已添加?

简单地向 map 添加注释并不会放大该注释。您可以使用以下方法放大新添加的注释:

-(void)zoomInOnLocation:(CLLocationCoordinate2D)location
{
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location, 200, 200);
[self.map setRegion:[self.map regionThatFits:region] animated:YES];
}

关于ios - MKMapView addAnnotation 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21749602/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com