一直在寻找这一点,但我似乎无法理解如何让用户当前的位置变成Google地图的URL,以打开Google地图应用程序,并填充指示。在Google地图openURL中使用位置管理器中的当前位置?
我已经从另一个教程中获取这段代码并将其添加到我的应用中。我需要从下面的“开始”lat/lng进入我的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]];
}
}
我已经在另一个应用程序之前这样做,但这种观点包含显示这让我得到纬度/经度容易的用户位置的地图。
在此先感谢。
位置是在我的模拟器的工作。位置更新背后的想法是,如果人们朝着/远离目的地的方向行驶,它会打开Google地图,并在最近的位置不到一分钟前发出指示。 – 2010-10-07 15:36:31