百度地图

<span style="font-size:24px;">1,显示当前位置的地图</span>
#import "ViewController2.h"
#import <BaiduMapAPI_Base/BMKBaseComponent.h>//引入base相关所有的头文件
#import <BaiduMapAPI_Map/BMKMapComponent.h>//引入地图功能所有的头文件
#import <BaiduMapAPI_Location/BMKLocationComponent.h>//引入定位功能所有的头文件
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>//引入计算工具所有的头文件
#import <BaiduMapAPI_Search/BMKSearchComponent.h>//引入检索功能所有的头文件
@interface ViewController2 ()<BMKMapViewDelegate,BMKLocationServiceDelegate,BMKGeoCodeSearchDelegate>{
    UITableView *mytable;
    IBOutlet BMKMapView* _mapView;
    BMKLocationService *_locService;
    UILabel *lb;
    CLLocationDistance      l;
    CLLocationDistance      v;
    BMKGeoCodeSearch        *_search;
}


@end

@implementation ViewController2

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title =@"消息";
    mytable =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view                                                          .frame.size.height)];
    mytable.backgroundColor =[UIColor whiteColor];
    mytable.separatorStyle =UITableViewCellSeparatorStyleNone;
    [self.view addSubview:mytable];
    [self initSth];
    lb =[[UILabel alloc]initWithFrame:CGRectMake(20, 100, 280, 160)];
    lb.textColor =[UIColor blackColor];
    lb.textAlignment =NSTextAlignmentCenter;
    [mytable addSubview:lb];
    _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [mytable addSubview:_mapView];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    _locService.delegate = self;
    _search.delegate = self;
    _mapView.delegate = self;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    _search.delegate = nil;
    _locService.delegate = nil;
    _mapView.delegate = self;
}

- (void)initSth{
    _locService = [[BMKLocationService alloc]init];
    _locService.delegate = self;
    [_locService startUserLocationService];
    _search = [[BMKGeoCodeSearch alloc]init];
    _search.delegate = self;
}

- (void)locateIf{
    NSString *addString = [[NSUserDefaults standardUserDefaults] objectForKey:@"addressString"];
    if (addString.length <= 0 || [addString isEqualToString:@"(null)"] || [addString isEqualToString:@"null"]) {
        lb.text = [NSString stringWithFormat:@""];
        [_locService startUserLocationService];
        [self startLocationServices];
    }else{
        lb.text = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"addressString"]];
    }
    [mytable reloadData];
    return;
}

- (void)startLocationServices{
    self.mapView.showsUserLocation = YES;
}

- (void)stopLocationServices{
    [_locService stopUserLocationService];
}

- (void)didFailToLocateUserWithError:(NSError *)error{
    NSLog(@"location error");
}

- (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error{
    NSLog(@"%@",result);
    lb.text = [NSString stringWithFormat:@"%@",result.address];
    lb.text  = [NSString stringWithFormat:@"%@",result.address];
    [mytable reloadData];
    [self stopLocationServices];
}

- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation{
    NSLog(@"定位");
}

- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation{
    if (userLocation != nil) {
        l = _locService.userLocation.location.coordinate.latitude;//得到纬度
        v = _locService.userLocation.location.coordinate.longitude;//得到经度
        CLLocationCoordinate2D pt = (CLLocationCoordinate2D){l, v};//此处填写想要反地理编码的坐标
        BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init];
        reverseGeocodeSearchOption.reverseGeoPoint = pt;
        BOOL flag = [_search reverseGeoCode:reverseGeocodeSearchOption];
        _mapView.centerCoordinate = userLocation.location.coordinate;
//        [_mapView setZoomLevel:15];
        if(flag){
            NSLog(@"反geo检索发送成功");
        }
        else{
            NSLog(@"反geo检索发送失败");
        }
    }
}

@end


2,显示定位

#import "ViewController3.h"
#import <BaiduMapAPI_Base/BMKBaseComponent.h>//引入base相关所有的头文件
#import <BaiduMapAPI_Map/BMKMapComponent.h>//引入地图功能所有的头文件
#import <BaiduMapAPI_Location/BMKLocationComponent.h>//引入定位功能所有的头文件
#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>//引入计算工具所有的头文件
#import <BaiduMapAPI_Search/BMKSearchComponent.h>//引入检索功能所有的头文件
@interface ViewController3 ()<BMKMapViewDelegate,BMKLocationServiceDelegate,BMKGeoCodeSearchDelegate>{
    UITableView *mytable;
    IBOutlet BMKMapView* _mapView;
    BMKLocationService *_locService;
    UILabel *lb;
    CLLocationDistance      l;
    CLLocationDistance      v;
    BMKGeoCodeSearch        *_search;
}


@end

@implementation ViewController3

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title =@"消息";
    mytable =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, self.view                                                          .frame.size.height)];
    mytable.backgroundColor =[UIColor whiteColor];
    mytable.separatorStyle =UITableViewCellSeparatorStyleNone;
    [self.view addSubview:mytable];
    [self initSth];
    lb =[[UILabel alloc]initWithFrame:CGRectMake(20, 100, 280, 160)];
    lb.textColor =[UIColor blackColor];
    lb.textAlignment =NSTextAlignmentCenter;
    [mytable addSubview:lb];
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    _locService.delegate = self;
    _search.delegate = self;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    _search.delegate = nil;
    _locService.delegate = nil;
}

- (void)initSth{
    _locService = [[BMKLocationService alloc]init];
    _locService.delegate = self;
    [_locService startUserLocationService];
    _search = [[BMKGeoCodeSearch alloc]init];
    _search.delegate = self;
}

- (void)locateIf{
    NSString *addString = [[NSUserDefaults standardUserDefaults] objectForKey:@"addressString"];
    if (addString.length <= 0 || [addString isEqualToString:@"(null)"] || [addString isEqualToString:@"null"]) {
        lb.text = [NSString stringWithFormat:@""];
        [_locService startUserLocationService];
        [self startLocationServices];
    }else{
        lb.text = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"addressString"]];
    }
    [mytable reloadData];
    return;
}

- (void)startLocationServices{
    self.mapView.showsUserLocation = YES;
}

- (void)stopLocationServices{
    [_locService stopUserLocationService];
}

- (void)didFailToLocateUserWithError:(NSError *)error{
    NSLog(@"location error");
}

- (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error{
    NSLog(@"%@",result);
    lb.text = [NSString stringWithFormat:@"%@",result.address];
    lb.text  = [NSString stringWithFormat:@"%@",result.address];
    [mytable reloadData];
    [self stopLocationServices];
}

- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation{
    NSLog(@"定位");
}

- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation{
    if (userLocation != nil) {
        l = _locService.userLocation.location.coordinate.latitude;//得到纬度
        v = _locService.userLocation.location.coordinate.longitude;//得到经度
        CLLocationCoordinate2D pt = (CLLocationCoordinate2D){l, v};//此处填写想要反地理编码的坐标
        BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init];
        reverseGeocodeSearchOption.reverseGeoPoint = pt;
        BOOL flag = [_search reverseGeoCode:reverseGeocodeSearchOption];
        if(flag){
            NSLog(@"反geo检索发送成功");
        }
        else{
            NSLog(@"反geo检索发送失败");
        }
    }
}

@end


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Flutter百度地图是一款基于Flutter技术开发的地图应用程序。Flutter是一种跨平台的移动应用开发框架,而百度地图是一款功能强大的地图导航工具。这个应用程序结合了Flutter的跨平台特性和百度地图的功能,使得开发者可以轻松地创建出高性能、交互友好的地图应用。 使用Flutter百度地图可以实现很多功能,比如显示地图、标记位置、搜索地点、路线规划等。开发者可以通过调用Flutter百度地图提供的API来完成这些功能。Flutter百度地图API包括了地图的展示、交互、搜索、定位等功能,能够满足开发者对地图应用的各种需求。 使用Flutter百度地图进行地图展示时,开发者可以自定义地图样式,包括地图的颜色、标注点的图片、文字样式等。通过调用API,开发者可以在地图上添加标记点、覆盖物、绘制路线等,使得地图更加丰富多样。此外,开发者还可以利用Flutter百度地图的搜索功能,实现地点的搜索和周边兴趣点的展示。 在开发过程中,Flutter百度地图提供了丰富的事件回调,开发者可以根据用户的交互行为来执行相应的操作。比如,当用户点击地图上的标记点时,开发者可以通过事件回调来实现弹出详情信息或执行其他特定操作。 总之,Flutter百度地图是一款强大的地图应用开发工具,可以帮助开发者快速构建出高质量的跨平台地图应用。无论是需要简单的地图展示,还是复杂的路线规划,Flutter百度地图都能满足开发者的需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值