0

配列からmapViewに注釈を表示するloopステートメントがあります。配列内の座標のいずれかが0,0であるかどうかを確認するにはどうすればよいですか?ある場合は、それらを削除/プロットしないでください。

ありがとう。

コード:

        CLLocationCoordinate2D maxCoord = {45.60250f,-122.39181f};
        CLLocationCoordinate2D minCoord = {45.35697f,-123.12789f};

        NSArray *callsArray = [xmlParser calls];

        for (JointCAD *call in callsArray) {
            NSString *callnumber = [call.callnumber stringByAppendingFormat:@". "];
            NSString *callandnumber = [callnumber stringByAppendingString:call.currentCallType];
            CLLocationCoordinate2D newCoord = { [call.latitude doubleValue], [call.longitude doubleValue]};

            if ([call.longitude doubleValue] > maxCoord.longitude)
            {
                maxCoord.longitude = [call.longitude doubleValue];
            }
            if ([call.latitude doubleValue] > maxCoord.latitude)
            {
                maxCoord.latitude = [call.latitude doubleValue];
            }
            if ([call.longitude doubleValue] < minCoord.longitude)
            {
                minCoord.longitude = [call.longitude doubleValue];
            }
            if ([call.latitude doubleValue] < minCoord.latitude)
            {
                minCoord.latitude = [call.latitude doubleValue];
            }

            Annotation *ann = [[Annotation alloc] init];
            ann.title = callandnumber;
            ann.subtitle = [call location];
            ann.coordinate = newCoord;
            [mapView addAnnotation:ann];
        }

        MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}};

        region.center.longitude = (minCoord.longitude + maxCoord.longitude) / 2.0;
        region.center.latitude = (minCoord.latitude + maxCoord.latitude) / 2.0;

        region.span.longitudeDelta = (maxCoord.longitude - minCoord.longitude) * 1.1;
        region.span.latitudeDelta = (maxCoord.latitude - minCoord.latitude) * 1.1;

        [mapView regionThatFits:region];
        [self.mapView setRegion:region animated:YES];

        [self setRefreshState:@"Finished"];
4

1 に答える 1

1

うーん、座標が0のときにループにacontinueを追加してみませんか?for

オブジェクトを作成する前Annotationに、単純なものを追加するだけです

if(newCoord.latitude == 0 && newCoord.longitude == 0) continue;

continueループの次の反復にスキップするだけです。

于 2012-10-20T18:15:14.300 に答える