「地図が利用できません」というメッセージが表示されているAppleマップを使用しているアプリがあります。興味のある点がいくつかあります。そのうちの1つをタップすると、それをタップすると、Apple Maps Applicationが開き、ナビゲートします。URLWithStringでGoogle Mapsを呼び出す
問題は、最初のタップ/スタート時にアプリケーションがApple Mapsを開きますが、ユーザーの場所の使用許可を求められていない場合でもAppleマップが機能せず、これらの場所の間に方向性が見つかりませんでした。しかし一般設定で私のアプリの位置情報サービスはONに設定されています。
私のアプリではナビゲーション用のデータを解析するのに時間がかかりすぎます(私はxmlからデータを取得しますが)2回目のタップですべてがうまく動作するため、Macから実行したとしてもデバッグモードで(xmlを2度目でも解析します)...
私はうまく説明したいと思います。何かヒント?
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinView == nil) pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorRed;
UIButton *myAccessoryButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
[myAccessoryButton setBackgroundColor:[UIColor clearColor]];
[myAccessoryButton setImage:[UIImage imageNamed:@"flag.png"] forState:UIControlStateNormal];
pinView.rightCalloutAccessoryView = myAccessoryButton;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
[myAccessoryButton release];
}
else {
[mapView.userLocation setTitle:@"You're here"];
}
return pinView;
}
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
// Configure the new event with information from the location
CLLocationCoordinate2D coordinate = [location coordinate];
NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];
CLLocationCoordinate2D start = { [latitude floatValue], [longitude floatValue] };
CLLocationCoordinate2D end = {[posto.latitude floatValue], [posto.longitude floatValue]};
NSString *googleMapsURLString = [NSString stringWithFormat:@"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f", start.latitude, start.longitude, end.latitude, end.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURLString]];
}
あなたが私に言った訂正をしましたが、現在、ユーザーの場所を使用する権限を適切に要求し、ループの一種を入力します。マップから常にdidUpdateToLocationメソッドに入るアプリケーションに移動します。何か? – Miwi
はい、忘れてしまいました:openURLを呼び出す前に '[locationManager stopUpdatingLocation];を実行してください。そうしないと、アプリに戻って再び場所を更新し、Mapsアプリに戻ります。 – Anna