【发布时间】:2010-10-07 15:25:38
【问题描述】:
今天一直在研究这个问题,但我似乎无法理解如何将用户当前位置输入 Google 地图 URL 以打开填充了方向的 Google 地图应用。
我已从另一个教程中获取此代码并将其添加到我的应用程序中。我需要将下面的“开始”纬度/经度输入到我的 IBAction 中才能打开 Google 地图应用。
- (void)locationUpdate:(CLLocation *)location {
// Lat/Lng of user (Needs to be sent to IBAction for btnDirections)
CLLocationCoordinate2D start = { location.coordinate.latitude, location.coordinate.longitude };
}
以下是我的“获取路线”按钮的 IBAction。
- (IBAction) onButtonClick:(id) sender {
if(sender == btnDirections) {
CLLocationCoordinate2D destination = { 52.48306771095311, -1.8935537338256836 };
NSString *googleMapsURLString = [NSString stringWithFormat:@"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f",
newLocation.coordinate.latitude, newLocation.coordinate.longitude, destination.latitude, destination.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURLString]];
}
}
我之前在另一个应用程序中做过此操作,但是该视图包含显示用户位置的地图,这使我可以轻松获取纬度/经度。
提前致谢。
【问题讨论】:
标签: iphone