2011-07-16 14 views
1

私はiPhoneのMapKitに助けが必要です! インタフェースビルダーを使用して簡単なマップビューを作成し、show userの場所をyesに設定しました。 しかし、配備したitouchに「青い点」が表示されません!私はそれに助けが必要です!iphone現在の位置は表示されません

また、どのようにしてユーザーの現在地を取得し、別の場所へのルートをプロットすることができますか? リンゴのマップアプリの使い方のような使い方の公式APIはありませんか?ルートを描く。

ありがとうございました!

マイコード。

のviewDidLoad

- (void)viewDidLoad { 
    locationManager = [[CLLocationManager alloc] init]; 
    [locationManager setDelegate:self]; 
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest]; 
    [locationManager startUpdatingLocation]; 
    [super viewDidLoad]; 
} 

locationManager:didUpdateToLocation:fromLocation:点2については

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 

    [mapView setMapType:MKMapTypeStandard]; 
    mapView.showsUserLocation = YES; 

    MKCoordinateRegion region; 

    CLLocationCoordinate2D location; 
    location.latitude = newLocation.coordinate.latitude; 
    location.longitude = newLocation.coordinate.longitude; 

    region.center = location; 
    region.span.longitudeDelta = 0.02; 
    region.span.latitudeDelta = 0.02; 
    [mapView setRegion:region animated:YES]; 
    [mapView setDelegate:self]; 
} 

答えて

1

:あなたはショーにマップでルートをしたい場合(そのアプリケーションがバックグラウンドで行きます)使用:

NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f",fromLocation.latitude, fromLocation.longitude,toLocation.latitude,toLocation.longitude]; 
      [[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]]; 

MKMapviewでルートを描きたい場合は、このhttps://github.com/kishikawakatsumi/MapKit-Route-Directionsを見ることをお勧めします。

ポイント1についてわからない、設定でロケーションサービスを有効にしていますか?

0

あなたは以下の方法で何を書きましたか?ユーザーの現在地に青い点またはピンを配置します。

注:あなたの必要に応じて変更する必要があるので、コードをコピーして貼り付けます。要するに、注釈がユーザの現在の位置である場合、ビューnilを返すだけでよい。次に、ユーザーの現在地に青い点が中央に自動的に表示されます。

- (MKAnnotationView *)mapView:(MKMapView *)MapView viewForAnnotation:(id<MKAnnotation>)annotation 
{ 
MKPinAnnotationView *view = nil; 

if(annotation !=mapview.userLocation){ 
    view = (MKPinAnnotationView *) 
    [mapview dequeueReusableAnnotationViewWithIdentifier:@"identifier"]; 
    if(nil == view) { 
     view = [[[MKPinAnnotationView alloc] 
       initWithAnnotation:annotation reuseIdentifier:@"identifier"] 
       autorelease];   
    } 
    [view setPinColor:MKPinAnnotationColorPurple]; 
    UIButton *btnViewVenue = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    btnViewVenue.frame = CGRectMake(0, 0, 30, 30); 
    view.rightCalloutAccessoryView=btnViewVenue; 
    view.pinColor = MKPinAnnotationColorGreen; 
    view.enabled = YES; 
    view.canShowCallout = YES; 
    view.multipleTouchEnabled = NO; 
    view.animatesDrop = YES; 
    }  
return view; 
} 

2つ目のポイントは、2つの場所の間のルートを描くことです。私の知る限りでは、手動で線を引くまで、そしてすべてのルートの座標がある場合は、MapKitの2つの場所の間のルートを公式に表示することは公式には不可能です。

このヘルプが必要です。

関連する問題