lsp*_*lsp 8 objective-c mapkit ios5 ios6 ios6-maps
这是一个奇怪的问题:我的应用程序应该能够调用iOS中的内置地图(包括5.1和6).事实证明它在iOS6下工作得很好,但在iOS5.1下却没有.调用iOS6中的地图,并跟踪从saddr到daddr的路线,但是当我在iOS5中时,地图应用程序被调用,但只有一个引脚放在daddr上.由于某种未知原因,初始坐标(saddr)没有显示,也没有跟踪方向.
这是我的代码:
addr = [NSString stringWithFormat: @"maps://saddr=%f,%f&daddr=%f,%f", newLocation.coordinate.latitude, newLocation.coordinate.longitude, oldLatitude, oldLongitude];
NSURL *url = [NSURL URLWithString:addr];
[[UIApplication sharedApplication] openURL:url];
Run Code Online (Sandbox Code Playgroud)
我尝试将网址更改为"http://maps.google.com/something",但它会调用Safari而不是内置的地图应用.我注意到变量正在正确传递给URL.
有任何想法吗?
提前致谢!
dir*_*ill 35
我有类似的问题,我不得不创建一些条件操作系统代码来处理谷歌地图应用程序已被删除的事实.来自新的MKMapItem参考
//first create latitude longitude object
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude,longitude);
//create MKMapItem out of coordinates
MKPlacemark* placeMark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil];
MKMapItem* destination = [[MKMapItem alloc] initWithPlacemark:placeMark];
if([destination respondsToSelector:@selector(openInMapsWithLaunchOptions:)])
{
//using iOS6 native maps app
[destination openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}];
}
else
{
//using iOS 5 which has the Google Maps application
NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=Current+Location&daddr=%f,%f", latitude, longitude];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
}
[placeMark release];
[destination release];
Run Code Online (Sandbox Code Playgroud)
要获得步行路线:
MKLaunchOptionsDirectionsModeWalking而不是MKLaunchOptionsDirectionsModeDriving&dirflg=w到网址.我认为在iOS6中使用openInMapsWithLaunchOptions会更好,因为它可以让您完全控制地图应用程序的响应方式.
| 归档时间: |
|
| 查看次数: |
11321 次 |
| 最近记录: |