你好朋友在我的应用程序中,我在 mapview 上显示了多个图钉。我有两个可变数组,第一个用于纬度,第二个用于经度,每个数组有 10 个值,因为我在我的方法中显示以下代码:
- (void)showAddressAllBusiness {
annotationsarray=[[NSMutableArray alloc] init];
NSLog(@"%d",[listOfLatitude count]);
NSLog(@"%d",[listOfLongitude count]);
NSLog(@"%d",[listOfPlaceName count]);
for (int i =0;i < [listOfLatitude count]; i++) {
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = [[listOfLatitude objectAtIndex:i] doubleValue];
region.center.longitude = [[listOfLongitude objectAtIndex:i] doubleValue];
region.span.longitudeDelta = 0.1f;
region.span.latitudeDelta = 0.1f;
[self.mapViewCityGuide setRegion:region animated:YES];
[self.mapViewCityGuide setZoomEnabled:YES];
addAnnotation = [[AddressAnnotation alloc]init];
addAnnotation.mTitle = [NSString stringWithFormat:@"%@",[listOfPlaceName objectAtIndex:i]];
addAnnotation.coordinate = region.center;
[self.mapViewCityGuide addAnnotation:addAnnotation];
[annotationsarray addObject:addAnnotation];
}
NSLog(@"%d",[self.mapViewCityGuide.annotations count]);
[self centerMap];
}
当我使用从 web 服务出现的纬度和经度数组值时,此代码无法正常工作,我正在调试代码,然后 mapViewCityGuide 得到 nil 或 0x0。
如果我在数组中使用硬编码纬度和经度值并调用此方法,那么它将在地图上显示所有引脚我该如何解决这个问题
listOfPlaceName = [[NSMutableArray alloc] initWithObjects:@"test",@"test",@"test",@"pithempur",@"test",@"test",@"test",@"test", nil];
listOfLatitude = [[NSMutableArray alloc] initWithObjects:@"22.71957",@"23.17930",@"22.96123",@"22.60987",@"22.45260",@"22.55244",@"22.60000",@"22.68330", nil];
listOfLongitude = [[NSMutableArray alloc] initWithObjects:@"75.85773",@"75.78491",@"76.05141",@"75.69644",@"75.94197",@"75.75653",@"75.30000",@"75.61670", nil];
[self showAddressAllBusiness];