【发布时间】:2011-03-16 11:49:22
【问题描述】:
我正在创建一个应用程序,我想在其中获取用户的当前位置并将其显示在地图上,当用户从当前位置到达目标位置时,目标位置也应该在地图中指向沿着行进方向。 在我的 xib 中,我添加了一个按钮 & on action(showDirectionsToHere) 按钮,我称之为 map 我在我的 appdelegate 中添加了以下代码,但它给了我一个错误:
- (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
}
在操作的第 1 行(showDirectionsHere)我得到无效初始化程序的错误 在第 2 行中,我收到 newLocation 未声明的错误。 请帮帮我
【问题讨论】:
标签: iphone objective-c mapkit core-location