简体   繁体   English

CLLocationCoordinate2D和NSMutableArray

[英]CLLocationCoordinate2D and NSMutableArray

I have two NSMutableArray, first keeps some location's latitudes and second keeps longitudes. 我有两个NSMutableArray,第一个保留某些位置的纬度,第二个保留经度。 Then, I want to see this locations on map with markers. 然后,我想在地图上用标记查看此位置。 This code shows one point on map but I have several points at NSMutableArray. 这段代码在地图上显示了一个点,但是我在NSMutableArray上有几个点。 How can I do this? 我怎样才能做到这一点? Is there anyone help me? 有没有人帮助我?

- (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.

}

You need to create annotation for each lat-lon and add to the mapview. 您需要为每个纬度创建注释,并将其添加到mapview。 Assuming your lat lon array in balance and order the algorithm can go like below. 假设您的纬度阵列处于平衡和顺序状态,则算法可以如下所示。

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