【问题标题】:iPhone: Press a button -> Centering the mapiPhone:按一个按钮 -> 使地图居中
【发布时间】:2011-05-30 12:06:27
【问题描述】:

我在我的 iPhone 应用中有一个 Google Maps 实现。首先,将地图设置为默认位置:

- (void)viewDidLoad {
    firstTimeUserLocationCentered = YES;
    [self moveToDefaultLocation];
    firstTimeUserLocationCentered = NO;
    ...
}

- (void)moveToDefaultLocation {
    MKCoordinateRegion myDefaultRegion;
    myDefaultRegion.center.latitude = defaultLocLat;
    myDefaultRegion.center.longitude = defaultLocLong;
    myDefaultRegion.span.latitudeDelta = defaultLocLatDelta;
    myDefaultRegion.span.longitudeDelta = defaultLocLongDelta;
    [self.myMapView setRegion:myDefaultRegion animated:YES];
}

如果用户允许应用可以使用他的位置,则调用此方法:

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
    if (!firstTimeUserLocationCentered) {
        MKCoordinateRegion myUserRegion;
        myUserRegion.span.latitudeDelta = userLocLatDelta;
        myUserRegion.span.longitudeDelta = userLocLongDelta;
        myUserRegion.center = userLocation.coordinate;
        [self.myMapView setRegion:myUserRegion animated:YES];
        firstTimeUserLocationCentered = YES;
    }
}

但是现在我有一个问题,我想集成一个按钮,所以按下它,位置应该在地图的中心。因此,如果用户允许应用程序使用该位置,则地图应居中于用户所在的位置,否则应使用默认位置,因此我可以致电[self moveToDefaultLocation]。 我该怎么做?

我也在寻找这个“用户位置居中”按钮的图标。在这张图片中,有一个我正在寻找的按钮图标:http://gadgetress.freedomblogging.com/files/2008/01/iphonemapslg.jpg“搜索”左侧的图标,我在哪里可以找到它?

最好的问候蒂姆。

【问题讨论】:

    标签: iphone objective-c mkmapview


    【解决方案1】:

    我解决了:

    MKUserLocation *myUserLocation = self.myMapView.userLocation;
    if (!myUserLocation.location) {
        [self moveToDefaultLocation];
    } else {
       self.mapView.centerCoordinate = self.mapView.myUserLocation.location.coordinate;
    }
    

    但是我没有找到这个图标...有谁知道我在哪里可以得到这个图标?

    【讨论】:

    • 使用setCenterCoordinate:animated: 获取动画(并使其类似于您的默认定位方法)。
    【解决方案2】:

    Glyphish 有几个地图图标,一个和你链接的那个一样。

    【讨论】:

      猜你喜欢
      • 2019-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-29
      • 2017-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多