How to center my current location in MKMapView?

后端 未结 4 1607
谎友^
谎友^ 2021-01-31 05:11

I am showing the current location in MKMapView by using showUserLocation enables. I also want to center the mapview to the us

相关标签:
4条回答
  • 2021-01-31 05:50

    for MKMapView

    self.mapView.showsUserLocation = YES;
    self.mapView.userTrackingMode = MKUserTrackingModeFollow;
    
    0 讨论(0)
  • 2021-01-31 05:57
    -(void) removeZoom:(float)deltaValue
    {
        MKCoordinateRegion region;
        region.center.latitude =  self.locationManager.location.coordinate.latitude;
        region.center.longitude = self.locationManager.location.coordinate.longitude;
    
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        region.span.latitudeDelta = deltaValue;
        region.span.longitudeDelta = deltaValue;
        region = [mapViewSelf regionThatFits:region];
        [mapViewSelf setRegion:region animated:YES];
        [UIView commitAnimations];
    
    }
    
    0 讨论(0)
  • 2021-01-31 06:05

    For centering on user location, you can use the following code:

    [mapView setCenterCoordinate:mapView.userLocation.location.coordinate animated:YES];
    

    For zooming on special locations, you should study how the regions (MKCoordinateRegion) are counted and work, count your values for the region and display it using call:

    [mapView setRegion:myRegion animated:YES];
    

    This sample WorldCities shows basics of region displaying.

    0 讨论(0)
  • 2021-01-31 06:08
    MKCoordinateRegion region;
        MKCoordinateSpan span;
        span.latitudeDelta = 0.2;     // 0.0 is min value u van provide for zooming
        span.longitudeDelta= 0.2;
    
        CLLocationCoordinate2D location = [self addressLocation];
        region.span=span;
        region.center =location;     // to locate to the center
        if(addAnnotation != nil) {
            [mapView removeAnnotation:addAnnotation];
            [addAnnotation release];
            addAnnotation = nil;
        }
        addAnnotation = [[AddressANnotation alloc] initWithCoordinate:location];
        [mapView addAnnotation:addAnnotation];
        [mapView setRegion:region animated:TRUE];
        [mapView regionThatFits:region];
    

    This had help me to show the position at the center of the map view.

    0 讨论(0)
提交回复
热议问题