繁体   English   中英

CLLocationCoordinate2D和NSMutableArray

[英]CLLocationCoordinate2D and NSMutableArray

我有两个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.

}

您需要为每个纬度创建注释,并将其添加到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 ends

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM