2010-04-05 114 views
0

我有一个启动谷歌地图应用程序的应用程序。代码是:CoreLocation当前位置

UIApplication *app = [UIApplication sharedApplication]; 
[app openURL:[[NSURL alloc] initWithString: @"http://maps.google.com/maps?daddr=Obere+Laube,+Konstanz,+Germany&saddr="]]; 

saddr =应该是当前位置。我得到的当前位置与

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

NSLog(@"%f,%f", [newLocation coordinate]); 

日志显示正确的坐标一样

2010-04-05 15:33:25.436 deBordeaux[60657:207] 37.331689,-122.030731 

我没有找到传送坐标到URL字符串的正确途径。有人可以给我一个提示吗?


嗯,我在我的.h

入口在我的方法我用“newLocation”,而不是你的“位置”。的代码是:

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

NSLog(@"%f,%f", [newLocation coordinate]); 
NSLog(@"%f", [newLocation coordinate].latitude); 

storedLocation = [newLocation coordinate]; 

NSLog(@"Standort neu String: %@", storedLocation); 

作为结果获得:

  • 2010-04-05 20:28:44.397 deBordeaux [64179:207] 37.331689,-122.030731
  • 2010-04-05 20:28:44.398 deBordeaux [64179:207] 37.331689
  • 编程接收信号:“EXC_BAD_ACCESS”。

回答

0

你不应该使用地址参数的URL,但LL

你应该通过纬度和经度

http://maps.google.com/maps?daddr=Obere+Laube,+Konstanz,+Germany&ll=37.331689,-122.030731 

,你可以从CLocation获得他们throught

[location coordinate].latitude 
[location coordinate].longitude 

编辑: 首先,你可以直接存储类型的对象CLLocationCoordinate2D,然后在需要时将其转换为NSString:

// in your .h 
CLLocationCoordinate2D storedLocation; 

// in your method 
storedLocation = [location coordinate]; 

// when you want to ask google maps 
[NSString stringWithFormat:@"http://maps.google.com/maps?daddr=Obere+Laube,+Konstanz,+Germany&ll=%f,%f", storedLocation.latitude, storedLocation.longitude]; 

记住,CLLocationCoordinate2D被定义为

typedef struct { 
    CLLocationDegrees latitude; 
    CLLocationDegrees longitude; 
} CLLocationCoordinate2D; 

,你必须typedef double CLLocationDegrees

+0

感谢您的快速答复。我了解“ll =”的用法,而不是“saddr =”。我的问题是,UIApplication ....的代码位于 - (IBAction)nav ...中,后面的位置坐标位于#pragma标记CLLocationManagerDelegate中。我找不到在NSString中“存储”位置坐标的方法。 – Christian 2010-04-05 17:45:52