我有一个启动谷歌地图应用程序的应用程序。代码是:
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-string的正确方法。有人可以给我一个提示吗?
在我的方法中,我使用“newLocation”而不是“location”。代码是:
-(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);
结果我得到了:
答案 0 :(得分:0)
您不应使用网址的 addr 参数,但 ll 。
您应该将纬度和经度作为
传递http://maps.google.com/maps?daddr=Obere+Laube,+Konstanz,+Germany&ll=37.331689,-122.030731
您可以从CLocation
通过
[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