我正在按照本教程(http://icodeblog.com/2009/12/21/introduction-to-mapkit-in-iphone-os-3-0/)向应用程序添加 mapkit 和注释。但是,我在用户位置上苦苦挣扎。我是 xcode 的新手,所以不太确定下一步该做什么。我试过托尼的选择:
step one: add the CoreLocation framework to the project.
Step two: add this function to the iCodeMapViewController.m:
- (void)setCurrentLocation:(CLLocation *)location {
MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}};
region.center = location.coordinate;
region.span.longitudeDelta = 0.15f;
region.span.latitudeDelta = 0.15f;
[self.mapView setRegion:region animated:YES];
}
step three: add this code to the ViewForAnnotation Method:
if (annotation != mapView.userLocation) {
//the rest of the ViewForAnnotation code goes here
}else{
CLLocation *location = [[CLLocation alloc]
initWithLatitude:annotation.coordinate.latitude
longitude:annotation.coordinate.longitude];
[self setCurrentLocation:location];
}
但是当我去建造时,它不喜欢它。
我也试过这个选项:
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation
{
if ([annotation isKindOfClass:MKUserLocation.class]) return nil;
//rest of code
}
蓝点显示,我的自定义注释显示,但是当我尝试滚动表格时应用程序崩溃。调试器没有提供任何帮助,但确实停止了此语句。
有人可以帮忙吗?也有代码示例?我认为这篇文章的答案可能对许多也在使用 mapkit 苦苦挣扎的人有用。
干杯