ios开发百度高德地图

高德开放平台
这里有两个地方可以参考,
https://lbs.amap.com/

屏幕快照 2019-04-11 下午4.36.06.png

屏幕快照 2019-05-09 下午1.38.26.png

百度开放平台
http://lbsyun.baidu.com/

屏幕快照 2019-04-11 下午4.38.34.png

0.选哪个
https://baijiahao.baidu.com/s?id=1616824316336369139&wfr=spider&for=pc

1.经纬度转换
https://blog.csdn.net/qq_35122556/article/details/80020370
2模拟定位
https://www.jianshu.com/p/f76fd7b19eac
这里有个问题:
定位之后手机要重启,不然你手机定位改不过来,
3。授权相关问题
https://www.jianshu.com/p/12e3f54fc0f7
4.带方向的定位小蓝点--高德地图ios
高德地图当前位置图标旋转功能实现-高德地图iOS
带箭头定位小蓝点-高德地图iOS

原理:手机的旋转角度-地图旋转角度,加个旋转动画

为什么贴代码呢,官方文档不是有么?因为官方文档上还有一些乱七八遭的东西,往往一个简单的功能非要让你阅读四五个乱七八糟的文件,特讨厌。

#import "ViewController.h"
#import <AMapFoundationKit/AMapFoundationKit.h>
#import <MAMapKit/MAMapKit.h>

static const NSUInteger kUserHearderAnnotaionViewTag = 10000;

@interface ViewController ()<MAMapViewDelegate,CLLocationManagerDelegate>

@property (nonatomic, strong) MAMapView *mapView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    [self creatMapView];
}

- (void)creatMapView {
    _mapView = [[MAMapView alloc]initWithFrame:self.view.bounds];
    _mapView.delegate = self;
    _mapView.showsCompass = NO;
    _mapView.showsUserLocation = YES;
  //  _mapView.userTrackingMode = MAUserTrackingModeFollow;
    //是否自定义用户位置精度圈
    _mapView.customizeUserLocationAccuracyCircleRepresentation = YES;
    [self.view addSubview:_mapView];
}

#pragma mark MAMapViewDelegate
- (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation
{
    NSLog(@"%f,%f,%f",userLocation.heading.x,userLocation.heading.y,userLocation.heading.z);
    
    //通过hearderAnnotationView的tag值拿到当前位置的annotationView
    MAAnnotationView *hearderAnnotationView = [self.mapView viewWithTag:kUserHearderAnnotaionViewTag];
    if (hearderAnnotationView)
    {
               //    hearderAnnotationView.transform = CGAffineTransformIdentity;
        CGFloat rotateDegree = userLocation.heading.trueHeading - _mapView.rotationDegree;
        
        //  CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI*userLocation.heading.magneticHeading/180.0);
        CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI*rotateDegree/180.0);
        hearderAnnotationView.transform = transform;

    }
}

- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation {
    //用户当前位置大头针
    if ([annotation isKindOfClass:[MAUserLocation class]])
    {
        static NSString *kUserLocationStyleReuseIndetifier = @"userLocationStyleReuseIndetifier";
        
        MAAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:kUserLocationStyleReuseIndetifier];
        
        if (annotationView == nil)
        {
            annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:kUserLocationStyleReuseIndetifier];
        }
        
        annotationView.canShowCallout = NO;
       annotationView.image = [UIImage imageNamed:@"当前位置"];
        annotationView.bounds = CGRectMake(0, 0, 27, 34.5);
        //annotationView.contentMode = UIViewContentModeScaleToFill;
        annotationView.layer.masksToBounds = YES;
        //设置当前位置大头针annotationView的tag值
        annotationView.tag = kUserHearderAnnotaionViewTag;
        
        return annotationView;
    }
    //其他大头针
    else if ([annotation isKindOfClass:[MAPointAnnotation class]]) {
        
        
    }
    return nil;
}
@end

https://www.jianshu.com/p/3979c3d3b12d这个链接就是上面代码的原版,有bug,都改好了。

1.上面的定位图标的大小
annotationView.bounds = CGRectMake(0, 0, 27, 34.5);

如果改成frame,回出先bug,大小回改变。不知到原因。不是        
annotationView.contentMode = UIViewContentModeScaleToFill;
的原因。
是它的原因:
        annotationView.frame = CGRectMake(0, 0, 27, 34.5);
2.旋转方向翻了
3.地图转了但是指针不转,

官方:
https://lbs.amap.com/dev/demo/location-rotation-effect#iOS
5.高德地图大头针自定义气泡
原理:自定义一个view,大头针addsubview 这个自定义的view;设置这个view的中心点,使它显示在大头针的上方。
5.1 地图显示大头针
百度
5.2代码
其他的不用管,只要在下面注释横线中间的地方添加代码

- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation
{
    if ([annotation isKindOfClass:[MAPointAnnotation class]])
    {
        static NSString *reuseIndetifier = @"annotationReuseIndetifier";
        CustomAnnotationView *annotationView = (CustomAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
        if (annotationView == nil)
        {
            annotationView = [[CustomAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIndetifier];
        }
        annotationView.image = [UIImage imageNamed:@"restaurant"];
        
       
        // 设置中心点偏移,使得标注底部中间点成为经纬度对应点
        annotationView.centerOffset = CGPointMake(0, -18);

//————————————这中间是要添加的大头针气泡————————————————————————//
        // 设置为NO,用以调用自定义的calloutView
        annotationView.canShowCallout = NO;
 UIView * aa = [[UIView alloc]init];
        aa.frame = CGRectMake(0, 0, 100, 50);
        //改变气泡位置,官方文档上的不用管
        aa.center = CGPointMake(CGRectGetWidth(annotationView.bounds) / 2.f + annotationView.calloutOffset.x,
                                              -CGRectGetHeight(aa.bounds) / 2.f + annotationView.calloutOffset.y);
        aa.backgroundColor = [UIColor redColor];
        
        
            [annotationView addSubview:aa];

 //------——————————————————————————————————————————————//
        return annotationView;
    }
    return nil;
}
##5.3气泡的图样
找美工要

6 高德地图跳转高德,百度,系统地图APP导航
6.1添加白名单

屏幕快照 2019-05-15 上午9.55.06.png

@property (nonatomic,assign) CLLocationDegrees latitudeSelf;//纬度自身
@property (nonatomic,assign) CLLocationDegrees longitudeSelf;//经度自身

@property (nonatomic,assign) CLLocationDegrees latitudePurpose;//纬度目的地
@property (nonatomic,assign) CLLocationDegrees longitudePurpose;//经度目的地
#pragma mark --小蓝点
- (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation
{
   //自身经纬度
    CLLocation *location = userLocation.location ;
     _latitudeSelf = location.coordinate.latitude;
     _longitudeSelf = location.coordinate.longitude;

}

#pragma mark --导航按钮
- (void)navigationBtn:(UIButton *)btn{
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"http://maps.apple.com/"]]) {//判断手机装原生地图app了么
        NSString *urlString=[NSString stringWithFormat:@"http://maps.apple.com/?saddr=%f,%f&daddr=%f,%f",_latitudeSelf,_longitudeSelf,_latitudePurpose,_longitudePurpose ];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:nil
                                 completionHandler:^(BOOL success) {

        }];
    }else if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]) {//高德
        NSString *urlString = [NSString stringWithFormat:@"iosamap://path?&sid=BGVIS1&slat=%f&slon=%f&did=BGVIS2&dlat=%f&dlon=%f&dev=0&t=0",_latitudeSelf,_longitudeSelf,_latitudePurpose ,_longitudePurpose] ;

        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:nil
                                 completionHandler:^(BOOL success) {

                                 }];
    }else if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]) {//百度

//高德地图坐标转百度地图坐标
    double pi = 3.1415926535897932384626;
    double x = _longitudePurpose ;
    double y = _latitudePurpose ;
    double z = sqrt(x * x + y * y) + 0.00002 * sin(y * pi);
    double theta = atan2(y, x) + 0.000003 * cos(x * pi);
    double mgLon1 = z * cos(theta) + 0.0065;
    double mgLat1 = z * sin(theta) + 0.006;
    //    //下标 1 为lat  下标 2 为lng

        NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=%f,%f&mode=riding&src=车辆", mgLat1,mgLon1] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:nil completionHandler:^(BOOL success) {

        }];

    }else{//都没有
        [[MBProgressHUDManager manger] showaAndHiddenWithText:@"请安装百度地图APP或高德地图APP或系统地图APP"];
   }
}

7.高德地图路径规划

官方:
https://lbs.amap.com/api/ios-sdk/guide/route-plan/walk

8.模糊搜索,联想搜索

#import <MAMapKit/MAMapKit.h>
#import <AMapSearchKit/AMapSearchKit.h>
#import <AMapFoundationKit/AMapFoundationKit.h>

@property (nonatomic, strong) AMapSearchAPI *search;//搜索


self.search = [[AMapSearchAPI alloc] init];
    self.search.delegate = self;

#pragma mark -- __________________________————————————————————点击事件
#pragma mark -- 搜索
- (void)searchCarClick:(UIButton *)sender{
    AMapInputTipsSearchRequest *tipsRequest = [[AMapInputTipsSearchRequest alloc] init];
    tipsRequest.keywords = @"五环";
    tipsRequest.city = @"北京";
    tipsRequest.cityLimit = YES;
    [_search AMapInputTipsSearch: tipsRequest];
}
#pragma mark --模糊搜索
-(void)onInputTipsSearchDone:(AMapInputTipsSearchRequest*)request response:(AMapInputTipsSearchResponse *)response
{
    if(response.tips.count == 0) {
        return;
    }
    NSMutableArray *tempArray = [NSMutableArray array];
    for (AMapTip *tip in response.tips) {
        
//        AdressModel *ads = [[AdressModel alloc]init];
//        ads.uid = tip.uid;
//        ads.name = tip.name;
//        ads.district = tip.district;
//        ads.address = tip.address;
//        ads.adcode = tip.adcode;
//        ads.latitude = tip.location.latitude;
//        ads.longitude = tip.location.longitude;
//        [tempArray addObject:ads];
        
    }
//    self.dataArray = [tempArray copy];
//    [_tableView reloadData];
}

9 百度 高德 gps 之间坐标系统相互转换

https://www.jianshu.com/p/27dbe24e8771

高德地图地理围栏:官网

判断一个点是否在多边形内:
https://www.jianshu.com/p/fb1177cac1ec

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,277评论 6 503
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,689评论 3 393
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,624评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,356评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,402评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,292评论 1 301
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,135评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,992评论 0 275
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,429评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,636评论 3 334
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,785评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,492评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,092评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,723评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,858评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,891评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,713评论 2 354

推荐阅读更多精彩内容