0

我正在按照本教程(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 苦苦挣扎的人有用。

干杯

4

2 回答 2

1

我有同样的问题,但我设法解决了。在 cellForRowAtIndexPath 我这样做了:


NSMutableArray *annotations = [[NSMutableArray alloc] init];
    if(indexPath.section == 0)
    {
        for(MinuAsukohad *annotation in [mapView annotations])
        {
            if(![annotation isKindOfClass:[MKUserLocation class]])
            {  
            if([annotation annotationType] == MinuAsukohadTypeInterest)
                {
                [annotations addObject:annotation];
                }
            }
        }
        cell.textLabel.text = [[annotations objectAtIndex:indexPath.row] title];
    }

你只需要对所有部分重复它。

于 2010-12-12T10:48:34.287 回答
0

听起来您正试图将您当前的位置作为表格中的一个单元格包含在内......查看您的控制台并在崩溃发生时向我们提供输出。

于 2010-11-27T18:30:49.307 回答