私は彼がいる場所のユーザーの現在の位置を取得し、地図上に表示するアプリケーションを作成しています。ユーザーが現在の目的地の場所に到達すると目的地の場所は旅行の方向に沿って地図内で指し示すべきである。 私XIBでは、私はマップ と呼ばれているボタンのアクションのボタン&(showDirectionsToHere)を追加している私は私のappdelegateに次のコードを追加しているが、それは私にエラーを与える:アクションの1行目でiphoneの地図上で現在地の位置を取得する方法
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation{
[manager stopUpdatingLocation];
printf("\n Latitude = " "\n Longitude = " " ",[NSString stringWithFormat:@"%.7f",newLocation.coordinate.latitude],[NSString stringWithFormat:@"%.7f",newLocation.coordinate.longitude]);
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CLLocationManager *locationManager = [[[CLLocationManager alloc]init]autorelease];
locationManager.delegate = self;
[locationManager startUpdatingLocation];
//[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
printf("\nerror");
}
- (IBAction)showDirectionsToHere {
CLLocationCoordinate2D currentLocation = [self getCurrentLocation]; // LINE 1
NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=old\%20Location&daddr=%f,%f", newLocation.latitude, newLocation.longitude];//Line 2
}
(showDirectionsHere)行2で無効な初期化子 のエラーが発生しましたが、newLocationが宣言されていないというエラーが発生します。 助けてください
IBAction)showDirectionsToHere { CLLocationCoordinate2D currentLocation = [自己getCurrentLocation]。 // LINE 1 NSString * url = [NSString stringWithFormat:@ "http://maps.google.com/maps?saddr=old\%20Location&daddr=%f,%f"、newLocation.latitude、newLocation.longitude] ; // Line 2 } getcurrentlocationはLocationManagerオブジェクトを返します – Rocky
getCurrentLocationメソッドのコードは? – visakh7
CLLocationCoordinate2D currentLocation = [self getCurrentLocation]; getCurrentLocationは、currentLocationに格納されているCLLocationCoordinate2D型のオブジェクトを返します。クラスを修正して場所を正しく取得する – visakh7