//
// toolViewController.m
// baiDuDemo
//
// Created by City--Online on 15/6/4.
// Copyright (c) 2015年 XQB. All rights reserved.
//
#import "toolViewController.h"
#import "BMKTypes.h"
#import "BMKGeometry.h"
#import "BMKNavigation.h"
#import "GTMBase64.h"
@interface toolViewController ()
@end
@implementation toolViewController
- (void)viewDidLoad {
[super viewDidLoad];
//判断两点距离
BMKMapPoint point1=BMKMapPointForCoordinate(CLLocationCoordinate2DMake(22.5538, 114.0672));
BMKMapPoint point2=BMKMapPointForCoordinate(CLLocationCoordinate2DMake(23.5538, 115.0672));
CLLocationDistance distance = BMKMetersBetweenMapPoints(point1,point2);
NSLog(@"%lf米",distance);
//坐标转换
CLLocationCoordinate2D test = CLLocationCoordinate2DMake(22.5538, 114.0672);
//转换 google地图、soso地图、aliyun地图、mapabc地图和amap地图所用坐标至百度坐标
NSDictionary* testdic = BMKConvertBaiduCoorFrom(test,BMK_COORDTYPE_COMMON);
//转换GPS坐标至百度坐标
testdic = BMKConvertBaiduCoorFrom(test,BMK_COORDTYPE_GPS);
NSLog(@"x=%@,y=%@",[testdic objectForKey:@"x"],[testdic objectForKey:@"y"]);
//base64 解密
NSString *y= [[NSString alloc] initWithData:[GTMBase64 decodeString:((NSString *)[testdic objectForKey:@"y"])] encoding:NSUTF8StringEncoding];
NSString *x= [[NSString alloc] initWithData:[GTMBase64 decodeString:((NSString *)[testdic objectForKey:@"x"])] encoding:NSUTF8StringEncoding];
NSLog(@"X=%@ Y=%@",x,y);
//base64加密
NSString *x1= [[NSString alloc] initWithData:[GTMBase64 encodeData:[x dataUsingEncoding:NSUTF8StringEncoding]] encoding:NSUTF8StringEncoding];
NSString *y1= [[NSString alloc] initWithData:[GTMBase64 encodeData:[y dataUsingEncoding:NSUTF8StringEncoding]] encoding:NSUTF8StringEncoding];
NSLog(@"%@ %@",x1,y1);
//导航
UIButton *btnnative=[UIButton buttonWithType:UIButtonTypeSystem];
[btnnative setTitle:@"客户端导航" forState:UIControlStateNormal];
btnnative.frame=CGRectMake(100, 100, 100, 100);
[btnnative addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
btnnative.tag=10001;
[self.view addSubview:btnnative];
UIButton *btnweb=[UIButton buttonWithType:UIButtonTypeSystem];
[btnweb setTitle:@"web导航" forState:UIControlStateNormal];
btnweb.frame=CGRectMake(100, 200, 100, 100);
[btnweb addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
btnweb.tag=10002;
[self.view addSubview:btnweb];
}
-(void)btnClick:(id)sender
{
UIButton *btn=(UIButton *)sender;
if (btn.tag==10001) {
//初始化调启导航时的参数管理类
BMKNaviPara* para = [[BMKNaviPara alloc]init];
//指定导航类型
para.naviType = BMK_NAVI_TYPE_NATIVE;
//初始化终点节点
BMKPlanNode* end = [[BMKPlanNode alloc]init];
//指定终点经纬度
CLLocationCoordinate2D coor2;
coor2.latitude = 22.5538;
coor2.longitude = 114.6072;
end.pt = coor2;
//指定终点名称
end.name = @"少年宫";
//指定终点
para.endPoint = end;
//指定返回自定义scheme,具体定义方法请参考常见问题
para.appScheme = @"baidumapsdk://mapsdk.baidu.com";
//调启百度地图客户端导航
[BMKNavigation openBaiduMapNavigation:para];
}
else if (btn.tag==10002)
{
//初始化调启导航时的参数管理类
BMKNaviPara* para = [[BMKNaviPara alloc]init];
//指定导航类型
para.naviType = BMK_NAVI_TYPE_WEB;
//初始化起点节点
BMKPlanNode* start = [[BMKPlanNode alloc]init] ;
//指定起点经纬度
// CLLocationCoordinate2D coor1;
// coor1.latitude = 22.5538;
// coor1.longitude = 114.6702;
// start.pt = coor1;
//指定起点名称
start.name = @"江苏大厦";
//指定起点
para.startPoint = start;
//初始化终点节点
BMKPlanNode* end = [[BMKPlanNode alloc]init] ;
// CLLocationCoordinate2D coor2;
// coor2.latitude = 22.5638;
// coor2.longitude = 114.6702;
// end.pt = coor2;
para.endPoint = end;
//指定终点名称
end.name =@"坂田地铁站";
//指定调启导航的app名称
para.appName = [NSString stringWithFormat:@"%@", @"baiDuDemo"];
//调启web导航
[BMKNavigation openBaiduMapNavigation:para];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end