gpt4 book ai didi

objective-c - 使用 Mapkit 和谷歌地图在 iPhone 中进行 GPS 路由(最短路径)

转载 作者:行者123 更新时间:2023-12-04 02:59:34 24 4
gpt4 key购买 nike

我正在 Xcode 4.3.3、iOS 5 上开发并使用 Mapkit 库。该应用应在 Google map 上显示当前位置、获取目的地地址并最终绘制出这两点之间的最短路径。

我使用本教程来实现应用程序,现在我有当前位置: http://blog.objectgraph.com/index.php/2009/04/02/iphone-sdk-30-playing-with-map-kit/

我寻找路由,但没有找到任何资源。请指导我如何绘制当前位置和目的地之间的最短路径。

谢谢!

最佳答案

你可以试试这只适用于 ios 6。

 Class itemClass = [MKMapItem class];
if (itemClass && [itemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) {

CLGeocoder *geocoder = [[CLGeocoder alloc] init];
CLLocation *newLocation = [[CLLocation alloc]initWithLatitude:getLatitude
longitude:getLongitude];

[geocoder reverseGeocodeLocation:newLocation
completionHandler:^(NSArray *placemarks, NSError *error) {

MKPlacemark *placeMark = [[MKPlacemark alloc] initWithPlacemark:[placemarks objectAtIndex:0]];

MKMapItem *mapItem = [[MKMapItem alloc]initWithPlacemark:placeMark];

MKMapItem *mapItem2 = [MKMapItem mapItemForCurrentLocation];

NSArray *mapItems = @[mapItem, mapItem2];

NSDictionary *options = @{
MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving,
MKLaunchOptionsMapTypeKey:
[NSNumber numberWithInteger:MKMapTypeStandard],
MKLaunchOptionsShowsTrafficKey:@YES
};

[MKMapItem openMapsWithItems:mapItems launchOptions:options];

} ];
}
else
{
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Failed to Get Your Location"delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];

}
}

关于objective-c - 使用 Mapkit 和谷歌地图在 iPhone 中进行 GPS 路由(最短路径),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11341499/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com