MapKitでユーザーの場所を表示しようとしています。これは、これまでで最も迷惑なことです。誰かが手を貸しますか?

StackOverflow https://stackoverflow.com/questions/4287745

質問

私はこのチュートリアルをフォローしています(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にも苦労している多くの人々にとって役立つかもしれないと思います。

乾杯

役に立ちましたか?

解決

私は同じ問題を抱えていましたが、それを解決することができました。 cellforrovatindexpathで私はこれをしました:


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];
    }

すべてのセクションに対して繰り返す必要があります。

他のヒント

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top