我有两个NSMutableArray,第一个保存某个位置的纬度,第二个保存经度。然后,我想在地图上看到这个带有标记的位置。这段代码显示了地图上的一个点,但我在NSMutableArray上有几个点。我该怎么做呢?有没有人帮帮我?
- (void)viewDidLoad
{
[super viewDidLoad];
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;
CLLocationCoordinate2D location;
location.latitude = 40.182533;
location.longitude = 29.066868;
region.span=span;
region.center=location;
if(addAnnotation != nil) {
[mapView removeAnnotation:addAnnotation];
[addAnnotation release];
addAnnotation = nil;
}
addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location];
[mapView addAnnotation:addAnnotation];
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
// Do any additional setup after loading the view from its nib.
}发布于 2011-10-05 17:03:01
您需要为每个经度创建注释,并添加到mapview。假设后面的数组在平衡和排序中,算法可以像下面这样进行。
Loop through your lat or lon array
CLLocationCoordinate2D location;
location.latitude = latArray[index];
location.longitude = lonArray[index];
addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location];
[mapView addAnnotation:addAnnotation];
Loop endshttps://stackoverflow.com/questions/7658472
复制相似问题