Как центрировать вид карты при отслеживании пользователя - PullRequest
0 голосов
/ 17 января 2012

Мне просто интересно, как центрировать вид карты, так как пользователь отслеживает вену с помощью CLLocationmanager и набора карт

В настоящее время я отслеживаю пользователя, обновляю местоположение и т. Д.

- (void)viewDidLoad
{
    // Initialize the TileOverlay with tiles in the application's bundle's resource directory.
    // Any valid tiled image directory structure in there will do.
    NSString *tileDirectory = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Tiles"];
    TileOverlay *overlay = [[TileOverlay alloc] initWithTileDirectory:tileDirectory];
    [map addOverlay:overlay];

    // zoom in by a factor of two from the rect that contains the bounds
    // because MapKit always backs up to get to an integral zoom level so
    // we need to go in one so that we don't end up backed out beyond the
    // range of the TileOverlay.
    MKMapRect visibleRect = [map mapRectThatFits:overlay.boundingMapRect];
    visibleRect.size.width /= 2;
    visibleRect.size.height /= 2;
    visibleRect.origin.x += visibleRect.size.width / 2;
    visibleRect.origin.y += visibleRect.size.height / 2;
    map.visibleMapRect = visibleRect;



//    map.showsUserLocation = YES;
    //location tracking
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];

    //Show the users location.. hopefully it works with tracking.
    map.showsUserLocation = YES;

    [overlay release]; // map is now keeping track of overlay
}

//OverLays Topographical map
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    TileOverlayView *view = [[TileOverlayView alloc] initWithOverlay:overlay];
    view.tileAlpha = 0.6;
    return [view autorelease];
}

//Tracks Users location and Prints out the Lat and Lon
-(void)locationManager:(CLLocationManager *)manager
   didUpdateToLocation:(CLLocation *)newLocation
          fromLocation:(CLLocation *)oldLocation
{
    CLLocationCoordinate2D here =  newLocation.coordinate;
    NSLog(@"%f  %f ", here.latitude, here.longitude);
}

Ответы [ 2 ]

4 голосов
/ 17 января 2012

Приведенный ниже метод фокусирует определенное место на карте,

//Don't forget to add this method to your header also
      -(void)focusLocationInMap:(CLLocationCoordinate2D)location
        {
        MKCoordinateRegion region;
        MKCoordinateSpan span;
        span.latitudeDelta=0.01;
        span.longitudeDelta=0.01;
        region.span=span;
        region.center=location;
        [self.yourMapView setRegion:region animated:TRUE];
        [self.yourMapView regionThatFits:region];
        }

Вы можете использовать его где угодно, передавая ему координаты,

CLLocationCoordinate2D here =  newLocation.coordinate;
[self focusLocationInMap:here];
1 голос
/ 17 января 2012

здесь. Координата не верна, должна быть просто "здесь"

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...