地图视图 - 移动地图视图后的当前位置

时间:2016-09-14 11:05:36

标签: ios iphone mkmapview

屏幕上的加载地图视图。

如果我们从左右移动地图

当我点击按钮

时,我需要立即在屏幕上显示当前位置

我使用以下代码初始获取当前位置

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{
    MKCoordinateRegion region =    MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800);
    [self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];

    // Add an annotation
    MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
    point.coordinate = userLocation.coordinate;
    point.title = @"Where am I?";
    point.subtitle = @"I'm here!!!";

    [self.mapView addAnnotation:point];
}

1 个答案:

答案 0 :(得分:1)

单击方法下方的按钮调用

  - (void)gotoLocation
    {
        float spanX = 0.05;
        float spanY = 0.05;
        MKCoordinateRegion region;
        region.center.latitude = mapView.userLocation.coordinate.latitude;
        region.center.longitude = mapView.userLocation.coordinate.longitude;
        region.span.latitudeDelta = spanX;
        region.span.longitudeDelta = spanY;
        [mapView setRegion:region animated:YES];
    }