0

アプリケーションへのマップキットと注釈の追加に関するこのチュートリアル ( http://icodeblog.com/2009/12/21/introduction-to-mapkit-in-iphone-os-3-0/ ) に従っています。ただし、ユーザーの場所に真剣に取り組んでいます。私は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
}

青い点が表示され、カスタム注釈が表示されますが、テーブルをスクロールしようとするとアプリがクラッシュします。デバッガーは助けを提供しませんが、このステートメントで停止します。

誰か助けてくれませんか?コード例も?この投稿への回答は、マップキットにも苦労している多くの人々に役立つと思います。

乾杯

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

現在の場所をテーブルのセルの 1 つとして含めようとしているように聞こえます...コンソールを見て、クラッシュが発生したときの出力を教えてください。

于 2010-11-27T18:30:49.307 に答える