iOS 根据地址名称 调取系统导航
2017-01-04 13:54
393 查看
- (IBAction)goNav:(id)sender {
__block
CLLocationCoordinate2D coordinate;
CLGeocoder *myGeocoder = [[CLGeocoder
alloc] init];
[myGeocoder geocodeAddressString:self.setTF.text
completionHandler:^(NSArray *placemarks,
NSError *error) {
if ([placemarks
count] > 0 && error ==
nil) {
NSLog(@"Found %lu placemark(s).", (unsigned
long)[placemarks
count]);
CLPlacemark *firstPlacemark = [placemarks
objectAtIndex:0];
NSLog(@"Longitude = %f", firstPlacemark.location.coordinate.longitude);
NSLog(@"Latitude = %f", firstPlacemark.location.coordinate.latitude);
coordinate = CLLocationCoordinate2DMake(firstPlacemark.location.coordinate.latitude,
firstPlacemark.location.coordinate.longitude) ;
}
else
if ([placemarks count] ==
0 && error == nil) {
NSLog(@"Found no placemarks.");
}
else
if (error != nil) {
NSLog(@"An error occurred = %@", error); }
}];
[CommonTool
gotoMapNavigationWithEndLocation:coordinate
andName:self.setTF.text];
}
+ (void)gotoMapNavigationWithEndLocation:(CLLocationCoordinate2D)endLocation andName:(NSString
*)name{
//起点
MKMapItem *currentLocation = [MKMapItem
mapItemForCurrentLocation];
//目的地的位置
MKMapItem *toLocation = [[MKMapItem
alloc] initWithPlacemark:[[MKPlacemark
alloc] initWithCoordinate:[CommonTool
GCJ02FromBD09:endLocation]
addressDictionary:nil]];
currentLocation.name =
@"我的位置";
toLocation.name = name;
NSArray *items = [NSArray
arrayWithObjects:currentLocation, toLocation,
nil];
NSDictionary *options =
@{ MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving,
MKLaunchOptionsMapTypeKey: [NSNumber
numberWithInteger:MKMapTypeStandard],
MKLaunchOptionsShowsTrafficKey:@YES
};
//打开苹果自身地图应用,并呈现特定的item
[MKMapItem
openMapsWithItems:items
launchOptions:options];
}
__block
CLLocationCoordinate2D coordinate;
CLGeocoder *myGeocoder = [[CLGeocoder
alloc] init];
[myGeocoder geocodeAddressString:self.setTF.text
completionHandler:^(NSArray *placemarks,
NSError *error) {
if ([placemarks
count] > 0 && error ==
nil) {
NSLog(@"Found %lu placemark(s).", (unsigned
long)[placemarks
count]);
CLPlacemark *firstPlacemark = [placemarks
objectAtIndex:0];
NSLog(@"Longitude = %f", firstPlacemark.location.coordinate.longitude);
NSLog(@"Latitude = %f", firstPlacemark.location.coordinate.latitude);
coordinate = CLLocationCoordinate2DMake(firstPlacemark.location.coordinate.latitude,
firstPlacemark.location.coordinate.longitude) ;
}
else
if ([placemarks count] ==
0 && error == nil) {
NSLog(@"Found no placemarks.");
}
else
if (error != nil) {
NSLog(@"An error occurred = %@", error); }
}];
[CommonTool
gotoMapNavigationWithEndLocation:coordinate
andName:self.setTF.text];
}
+ (void)gotoMapNavigationWithEndLocation:(CLLocationCoordinate2D)endLocation andName:(NSString
*)name{
//起点
MKMapItem *currentLocation = [MKMapItem
mapItemForCurrentLocation];
//目的地的位置
MKMapItem *toLocation = [[MKMapItem
alloc] initWithPlacemark:[[MKPlacemark
alloc] initWithCoordinate:[CommonTool
GCJ02FromBD09:endLocation]
addressDictionary:nil]];
currentLocation.name =
@"我的位置";
toLocation.name = name;
NSArray *items = [NSArray
arrayWithObjects:currentLocation, toLocation,
nil];
NSDictionary *options =
@{ MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving,
MKLaunchOptionsMapTypeKey: [NSNumber
numberWithInteger:MKMapTypeStandard],
MKLaunchOptionsShowsTrafficKey:@YES
};
//打开苹果自身地图应用,并呈现特定的item
[MKMapItem
openMapsWithItems:items
launchOptions:options];
}
相关文章推荐
- 根据参照名称生成参照面板_支持自定义参照和系统参照
- 软件项目或者产品有时候会用到本机网卡的物理MAC地址、IP地址、硬盘序列号加上使用软体名称和地址进行安全加密验证,例如结合MAC地址进行登录验证等等,当然这种项目一般在局域网内运行,能相对提高系统的安全性
- IOS调取系统摄像头以及相册
- 【学习ios之路:UI系列】获取通过UIImagePackerController获取的系统相册图片的名称信息及保存系统相册到本地
- IOS跳转到系统地图导航
- 思科IOS 史上最全IOS下载 并陆续提供单个下载地址 红色名称表示可以单独下载
- ios系统经纬度转百度经纬度及经纬度转地址
- ios应用程序多语言,根据系统语言
- iOS 根据地图上的点画线 画导航
- XE7 iOS 取得系统字型名称
- bash shell 根据系统硬件平台名称判断是否为 64 位平台
- windows server 2008系统IOS镜像下载地址
- ios根据视频地址获取某一帧的图像
- iOS:系统字体名称,经常用到
- unity基础开发----Unity获取PC,Ios系统的mac地址等信息
- linux_kernel_debug_tips_根据函数地址定位函数名称
- IOS调取系统摄像头并拍照
- 获取IOS设备的系统版本,硬件名称,mac地址
- ios根据视频地址获取某一帧的图像
- iOS_根据系统版本编译不同的代码