百度地图之计算工具

简介:

//
//  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



相关文章
|
JavaScript 前端开发 API
python对接API二次开发高级实战案例解析:百度地图Web服务API封装函数(行政区划区域检索、地理编码、国内天气查询、IP定位、坐标转换)
python对接API二次开发高级实战案例解析:百度地图Web服务API封装函数(行政区划区域检索、地理编码、国内天气查询、IP定位、坐标转换)
465 0
|
移动开发 小程序 JavaScript
微信小程序学习实录6(百度经纬度采集、手动调整精度、H5嵌入小程序、百度地图jsAPI、实时定位、H5更新自动刷新)
微信小程序学习实录6(百度经纬度采集、手动调整精度、H5嵌入小程序、百度地图jsAPI、实时定位、H5更新自动刷新)
236 1
|
移动开发 小程序 定位技术
小程序引入高德/百度地图坐标系详解
小程序引入高德/百度地图坐标系详解
468 0
|
定位技术 API
百度地图异步加载开发系列(7):计算两个坐标点距离的API
百度地图异步加载开发系列(7):计算两个坐标点距离的API
181 0
|
JavaScript 定位技术
百度地图实用案例
百度地图实用案例
|
Serverless
GEE基础学习——Hillshade山阴的计算和显示
GEE基础学习——Hillshade山阴的计算和显示
480 0
GEE基础学习——Hillshade山阴的计算和显示