如何在目标c中的地图上显示几个位置点 [英] How can I show several location points on map in objective c

查看:248
本文介绍了如何在目标c中的地图上显示几个位置点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个NSMutableArray,首先保留一些位置的纬度,第二个保持经度。然后,我想在地图上看到这个位置用标记。我尝试这样,但它不工作。如何做到这一点?

  for(int x = 0; x <= [ws8.Latitude count]; x ++){ 
for(int y = 0; y< = [ws8.Longitude count]; y ++){

CLLocationCoordinate2D location1;

location1.latitude = [[ws8.Latitude objectAtIndex:x] floatValue];
location1.longitude = [[ws8.Longitude objectAtIndex:y] floatValue];


region.span = span;
region.center = location1;

if(addAnnotation!= nil){
[mapView removeAnnotation:addAnnotation];
[addAnnotation release];
addAnnotation = nil;
}
addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location1];
[mapView addAnnotation:addAnnotation];
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
[mapView setShowsUserLocation:YES];
}
}


解决方案

每个纬度,你都是经度绘制的。我删除了内部循环。你可以尝试下面的代码,看看是否适用于你?

  for(int x = 0; x <= [ws8。纬度数]; x ++){
CLLocationCoordinate2D location1;

location1.latitude = [[ws8.Latitude objectAtIndex:x] floatValue];
location1.longitude = [[ws8.Longitude objectAtIndex:x] floatValue];


region.span = span;
region.center = location1;

// if(addAnnotation!= nil){
// [mapView removeAnnotation:addAnnotation];
// [addAnnotation release];
// addAnnotation = nil;
//}
addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location1];
[mapView addAnnotation:addAnnotation];
[addAnnotation release];
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
}


[mapView setShowsUserLocation:YES];


I have two NSMutableArray, first keeps some location's latitudes and second keeps longitudes. Then, I want to see this locations on map with markers. I try like this but it is not work. How can I do this?

    for (int x=0; x<=[ws8.Latitude count]; x++) {
    for (int y=0; y<=[ws8.Longitude count]; y++) {

        CLLocationCoordinate2D location1;

        location1.latitude = [[ws8.Latitude objectAtIndex:x] floatValue];
        location1.longitude = [[ws8.Longitude objectAtIndex:y] floatValue];


        region.span=span;
        region.center=location1;

        if(addAnnotation != nil) {
            [mapView removeAnnotation:addAnnotation];
            [addAnnotation release];
            addAnnotation = nil;
        }
        addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location1];
        [mapView addAnnotation:addAnnotation];
        [mapView setRegion:region animated:TRUE];
        [mapView regionThatFits:region];
        [mapView setShowsUserLocation:YES];
    }
}    

解决方案

for each latitude, you are mapping with ever longitude. I removed the inner loop. Can you try below code and see if that works for you?

for (int x=0; x<=[ws8.Latitude count]; x++) {
    CLLocationCoordinate2D location1;

    location1.latitude = [[ws8.Latitude objectAtIndex:x] floatValue];
    location1.longitude = [[ws8.Longitude objectAtIndex:x] floatValue];


    region.span=span;
    region.center=location1;

//        if(addAnnotation != nil) {
//            [mapView removeAnnotation:addAnnotation];
//            [addAnnotation release];
//            addAnnotation = nil;
//        }
    addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location1];
    [mapView addAnnotation:addAnnotation];
    [addAnnotation release];
    [mapView setRegion:region animated:TRUE];
    [mapView regionThatFits:region];
}


[mapView setShowsUserLocation:YES];

这篇关于如何在目标c中的地图上显示几个位置点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆