【发布时间】: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