0

アプリの地図画面には、ユーザーの現在地が表示されます。ユーザーがマップを「閲覧」できるようにしたい (スクロールして他のエリアを探索する) と、現在の場所でマップ上のポイントにユーザーを戻すボタンがありますがアプリがユーザーがマップを「ブラウズ」して見ているビューを保持することを許可せず、ユーザーの現在の場所にすぐに戻ります。

ここにいくつかのコードがあります:

-(void) setupLocation {
        locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
        //    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
        locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
        [locationManager startUpdatingLocation];
    }

    - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
    {
        NSLog(@"didFailWithError: %@", error);
    }

        - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    {
        //    [self.mapView setCenterCoordinate:self.mapView.userLocation.coordinate animated:YES];

        tempLat = newLocation.coordinate.latitude;
        tempLon = newLocation.coordinate.longitude;
        CLLocationCoordinate2D currentLocation = CLLocationCoordinate2DMake(tempLat, tempLon);
        MKCoordinateRegion viewRegionLocation = MKCoordinateRegionMakeWithDistance(currentLocation, 100, 100);
        [self.mapView setRegion:viewRegionLocation animated:YES];

        locationNew = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude];
        locationOld = [[CLLocation alloc] initWithLatitude:oldLocation.coordinate.latitude longitude:oldLocation.coordinate.longitude];

    }

私も持っています:

- (IBAction)stopUpdating:(id)sender {
    [locationManager stopUpdatingLocation];
}

と:

- (IBAction)findMe:(id)sender {
    [locationManager startUpdatingLocation];
}

マップがユーザーの現在の場所に戻り続ける理由についてのアイデアはありますか??

どうもありがとうございました!

4

1 に答える 1

1

- (void)locationManager: didUpdateToLocation: fromLocation: メソッド

では、マップビューの領域を毎回更新された場所に設定しているためです。

この部分を削除すると、問題が解決します。

  MKCoordinateRegion viewRegionLocation = MKCoordinateRegionMakeWithDistance(currentLocation, 100, 100);
  [self.mapView setRegion:viewRegionLocation animated:YES];

編集1:

この行を viewDidLoad メソッドに追加し、

self.mapView.showsUserLocation = YES;

このように検索ボタンの押し方を変更し、

-(IBAction) findMeButtonPressed:(id)sender;{
    MKCoordinateRegion viewRegionLocation = MKCoordinateRegionMakeWithDistance([self.locationManager location].coordinate, 100, 100);
    [self.mapView setRegion:viewRegionLocation animated:YES];
}
于 2013-05-12T07:08:00.287 に答える