【问题标题】:When i drop multiple pins in map depends on different latitude and longitude values. im getting all pins at one place only当我在地图中放置多个图钉时,取决于不同的纬度和经度值。我只在一个地方获得所有别针
【发布时间】:2013-02-15 07:36:31
【问题描述】:

当我在地图中放置多个图钉时,取决于不同的纬度和经度值。我得到所有图钉都在地图上的一个地方。

我编写了这段代码来删除多个引脚。

    dealerMapView.mapType = MKMapTypeStandard;
    dealerMapView.zoomEnabled =YES;
    [dealerMapView setDelegate:nil];
    dealerMapView.scrollEnabled = YES;
    dealerMapView.showsUserLocation = NO;
    CLLocationCoordinate2D location;

        for (int i =0; i<[delarsInfoArray count]; i++) {

            NSString *lattitudeValue = [[delarsInfoArray objectAtIndex:i]objectForKey:@"LATITUDE" ];

            NSString *longitudeValue = [[delarsInfoArray objectAtIndex:i]objectForKey:@"LONGITUDE" ];
            CLLocationCoordinate2D pCoordinate ;
    pCoordinate.latitude = [lattitudeValue floatValue];
    pCoordinate.longitude = [longitudeValue floatValue];
    MKCoordinateRegion region;
    MKCoordinateSpan span;
    span.latitudeDelta = 0.005;
    span.longitudeDelta = 0.005;
    region.span = span;
    region.center = location;
    [dealerMapView setRegion:region animated:YES];
    myAnnotation1 = [[MyAnnotation alloc] init];
    myAnnotation1.coordinate = location;
    myAnnotation1.title = [[delarsInfoArray objectAtIndex:i]objectForKey:@"STORE"]; 
    [dealerMapView addAnnotation:myAnnotation1];
}

【问题讨论】:

    标签: iphone ios ipad map pins


    【解决方案1】:

    试试这个代码:

    MKCoordinateSpan span;
    span.latitudeDelta = 0.2;
    span.longitudeDelta= 0.2;
    
    if( [delarsInfoArray count] > 0 ){
    
        CLLocationCoordinate2D start;
        NSString *lattitudeValue = [[delarsInfoArray objectAtIndex:0]objectForKey:@"LATITUDE" ];
    
        NSString *longitudeValue = [[delarsInfoArray objectAtIndex:j]objectForKey:@"LONGITUDE" ];
    
    // create region, consisting of span and location
        MKCoordinateRegion mapRegion;
        mapRegion.span = span;
        mapRegion.center = start;
    //Move the map to our location //
        [dealerMapView setRegion:mapRegion animated:YES];
    }
    // do not show pins and annotations more then 200 in the map at a time.
    for (int j = 0; j< ([delarsInfoArray count] < 200?[delarsInfoArray count]:200); j++) {
        NSString *lattitudeValue = [[delarsInfoArray objectAtIndex:i]objectForKey:@"LATITUDE"];
                NSString *longitudeValue = [[delarsInfoArray objectAtIndex:i]objectForKey:@"LONGITUDE" ];
    
        CLLocationCoordinate2D pinLocation;
        if(([lattitudeValue floatValue] != 0) && ([longitudeValue floatValue] != 0) ) {
            pinLocation.latitude = [lattitudeValue floatValue];
            pinLocation.longitude = [longitudeValue floatValue];
            if(pinLocation.latitude !=0 && pinLocation.longitude !=0) {
                myAnnotation1 = [[MyAnnotation alloc] init];
                myAnnotation1.coordinate = location;
                myAnnotation1.title = [[delarsInfoArray objectAtIndex:i] objectForKey: @"STORE"]; 
                [dealerMapView addAnnotation:myAnnotation1];
            }
        }
    }
    

    希望对你有帮助!!好运。干杯!!

    【讨论】:

    • 不客气!您在循环的每次迭代中都设置了地图区域。根据我的说法,这就是导致您遇到的问题的原因!!很高兴它对您有所帮助。
    猜你喜欢
    • 2015-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多