3

などを設定しましたmapView.delegate
すべて問題ありませんが、アプリを再開して数分後にアプリを終了すると終了します。

コンソールは私にこれを与えますが、私はそれを修正することができませんでした:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 
'Invalid Region <center:-180.00000000, -180.00000000 span:+0.09000000, +0.09000000>'

userLocationが更新された後setRegionにメソッドを送信するdidUpdateUserLocation

 - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    [mapView removeAnnotations: [mapView annotations]];
    for (TOJSearchItem *searchItem in _searchItems) {
        TOJPlaceRequest *request = [TOJPlaceRequest new];
        [request execute:SERVER_URL coordinate:userLocation.coordinate searchItem:searchItem delegate:self];
    }
    MKCoordinateRegion region = {{userLocation.coordinate.latitude , userLocation.coordinate.longitude}, {0.09f , 0.09f}};
    [mapView setRegion:region animated: YES];
}

リクエストする

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    if (_lastLocation != nil) {
        CLLocationDistance meters = [newLocation distanceFromLocation:_lastLocation];
        if (meters < DISTANCE_MINI) {
//            CALCUL tout les points par rapport a current location
//            NSLog(@"%f, %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
        } else {
            for (TOJSearchItem *searchItem in _searchItems) {
                TOJPlaceRequest *request = [TOJPlaceRequest new];
                [request execute:SERVER_URL coordinate:newLocation.coordinate searchItem:searchItem delegate:self];
            }
            MKCoordinateRegion region = {{newLocation.coordinate.latitude , newLocation.coordinate.longitude}, {0.09f , 0.09f}};
            [_mapView setRegion: region animated: YES];
            NSLog(@"reconnection");
        }
    }
    _lastLocation = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude];
}

注釈をクリックした後、領域をリセットします

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    if ([view class] == TOJClusterPushPinView.class) {
        TOJClusterPushPinView *clusterPushPinView = (TOJClusterPushPinView *)view;
        CLLocationCoordinate2D topLeftCoordinate;
        topLeftCoordinate.latitude = -90;
        topLeftCoordinate.longitude = 180;
        CLLocationCoordinate2D bottomRightCoordinate;
        bottomRightCoordinate.latitude = 90;
        bottomRightCoordinate.longitude = -180;
        for (TOJPushPin *pushPin in clusterPushPinView.clusterPushPin.pushPins) {
            topLeftCoordinate.longitude = fmin(topLeftCoordinate.longitude, pushPin.coordinate.longitude);
            topLeftCoordinate.latitude = fmax(topLeftCoordinate.latitude, pushPin.coordinate.latitude);
            bottomRightCoordinate.longitude = fmax(bottomRightCoordinate.longitude, pushPin.coordinate.longitude);
            bottomRightCoordinate.latitude = fmin(bottomRightCoordinate.latitude, pushPin.coordinate.latitude);
        }
        MKCoordinateRegion region;
        region.center.latitude = topLeftCoordinate.latitude - (topLeftCoordinate.latitude - bottomRightCoordinate.latitude) * 0.5;
        region.center.longitude = topLeftCoordinate.longitude + (bottomRightCoordinate.longitude - topLeftCoordinate.longitude) * 0.5;
        region.span.latitudeDelta = fabs(topLeftCoordinate.latitude - bottomRightCoordinate.latitude) * 2.0; // Add a little extra space on the sides
        region.span.longitudeDelta = fabs(bottomRightCoordinate.longitude - topLeftCoordinate.longitude) * 2.0; // Add a little extra space on the sides
        region = [mapView regionThatFits:region];
        [mapView setRegion:region animated:YES];
    }
}
4

3 に答える 3

0

didUpdateToLocationメソッドの場合は、指定されているロケーション変数が有効であることを確認する必要があります。

 if (userLocation.location.horizontalAccuracy >= 0) {

ロジックはわかりませんが、レジューム後に最初に取得する場所が無効である可能性があることは既知の動作です。精度が0未満の場所はすべて破棄する必要があります。

参照:http ://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocation_Class/CLLocation/CLLocation.html#//apple_ref/occ/instp/CLLocation/horizo​​ntalAccuracy

于 2012-10-15T19:56:07.093 に答える
0

への変更

 if (userLocation.location.horizontalAccuracy >= 1) {

 .......

 }

できます

于 2013-07-05T10:17:08.077 に答える
0

次の場合は、didUpdateUserLocationをチェックインする必要があります

userLocation.location != nil

私のアプリケーションでは、applicationDidBecomeActiveイベントから戻るとき、最初の座標は常に無効です。

于 2013-09-06T22:46:32.563 に答える