定位iOS百度地图反编码个人见解

反百度  时间:2021-01-31  阅读:()

iOS百度地图反编码个人见解

类似于微信中的发送位置拖拽从新定位以及反编码列表附近的位置。

百度地图拖拽更新位置.gif

思路就是将一个UIImageView 固定在地图中间每次更新位置给UIImageView添加劢画即可。

代码如下

#import "FTBasicControl ler.h"typedef void (^SelectBlock) (NSString *address,CLLocationCoordinate2D select);@interface FTUploadAddressControl ler : FTBasicControl ler

@property(nonatomic, copy)SelectBlock selectBlock;

@end

#import "FTUploadAddressControl ler.h"

#import "FTBMKPoiInfo.h"

#import "FTPoiCel l.h"

@interface FTUploadAddressControl ler

()<BMKMapViewDelegate,BMKLocationServiceDelegate,UITableViewDelegate,UITableViewDataSource,BMKGeoCodeSearchDelegate>

@property(nonatomic,strong)BMKLocationService *locService;

@property(nonatomic,strong)BMKUserLocation *userLocation;

@property(nonatomic,strong)BMKMapView*mapView;

@property(nonatomic,strong)UITableView*tableview;

@property(nonatomic,strong)BMKGeoCodeSearch *geocodesearch;

@property(nonatomic,strong)UIImageView*loactionView;

@property(nonatomic,strong)NSMutableArray*dataA;

@property(nonatomic,strong)LxButton *poiBackBtn;

@property(nonatomic,assign)CLLocationCoordinate2D selectedCoordinate;

@property(nonatomic,strong)NSString *selectAddress;

@end

@implementation FTUploadAddressControl ler

-(void)viewWi l lAppear:(BOOL)animated{

[superviewWi l lAppear:animated];self.fd_interactivePopDisabled =YES;if (!([CLLocationManager authorizationStatus] ==kCLAuthorizationStatusAuthorizedAlways | | [CLLocationManager authorizationStatus] ==

kCLAuthorizationStatusAuthorizedWhenInUse)&&[CLLocationManagerauthorizationStatus] != kCLAuthorizationStatusNotDetermined){

[self judgeOpenlocation] ;

}else{

[_mapView viewWi l lAppear] ;

_mapView.delegate = self; //此处记得丌用的时候需要置ni l 否则影响内存的释放

_locService.delegate = self;

_geocodesearch.delegate= self;//此处记得丌用的时候需要置ni l 否则影响内存的释放

_mapView.showsUserLocation= NO;//先关闭显示的定位图层

_mapView.userTrackingMode = 0;

_mapView.showsUserLocation=YES;//显示定位图层

[self. locService startUserLocationService] ;

}

}

-(void)judgeOpenlocation{

UIAlertControl ler *alertVC= [UIAlertControl ler alertControl lerWithTitle:@"打开[定位服务]来允许[应用名字]确定您的位置"message:@"请在系统设置中开启定位服务(设置>隐私>定位服务>应用名字>始终) "preferredStyle:UIAlertControl lerStyleAlert];

[alertVC addAction:[UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancel handler:ni l] ];

[alertVC addAction:[UIAlertActionactionWithTitle:@"去设置"style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnul l action) {if ([ [[UIDevice currentDevice] systemVersion] floatValue] >= 10.000000) {

//跳转到定位权限页面

NSURL *url = [NSURL URLWithString:UIAppl icationOpenSettingsURLString];if( [[UIAppl ication sharedAppl ication]canOpenURL:url] ) {

[[UIAppl ication sharedAppl ication]openURL:url] ;

}

}else{

//跳转到定位开关界面

NSURL *url = [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];if( [[UIAppl ication sharedAppl ication]canOpenURL:url] ) {

[[UIAppl ication sharedAppl ication]openURL:url] ;

}

}

}] ];

[self presentViewControl ler:alertVC animated:YES completion:ni l];

}

-(void)viewWi l lDisappear:(BOOL)animated

{self.fd_interactivePopDisabled = NO;

[_mapViewviewWi l lDisappear];

_mapView.delegate = ni l; //丌用时置ni l

[self. locService stopUserLocationService];

_geocodesearch.delegate = ni l ;//丌用时置ni l

_locService.delegate = ni l;

}

- (void)viewDid Load{

[superviewDidLoad];

//Doanyadditional setup after loading the view.self.title =@"所在位置";self. locService = [[BMKLocationService al loc] init] ;self.geocodesearch= [ [BMKGeoCodeSearchal loc] init];

[self setup];self.navigationItem. leftBarButtonItem=[[UIBarButtonItemal loc] initWithImage:[ [UIImageimageNamed:@"return"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(backReturn)];}

-(void)backReturn{if (self.selectBlock) {self.selectBlock(self.selectAddress, self.selectedCoordinate);

[self.navigationControl ler popViewControl lerAnimated:YES];

}

}

-(void)setup{

[self.viewaddSubview:self.mapView] ;

[self.viewaddSubview:self.tableview];

[self.mapViewaddSubview:self. loactionView];

[self.mapViewaddSubview:self.poiBackBtn] ;

[self.poiBackBtn LX_SetShadowPathWith:[UIColorgrayColor] shadowOpacity:0.5shadowRadius:5 shadowSide:LXShadowPathBottom shadowPathWidth:3];

FTWS(weakSelf);

[self.poiBackBtnaddCl ickBlock:^(UIButton *button) {

[weakSelf.mapViewsetCenterCoordinate:weakSelf.userLocation. location.coordinate];

}] ;

}

- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation

{

// NSLog(@"didUpdateUserLocationlat%f, long%f",userLocation. location.coordinate. latitude,userLocation. location.coordinate. longitude);

[_mapView updateLocationData:userLocation];self.userLocation = userLocation;

[self.mapViewsetCenterCoordinate:userLocation. location.coordinate];

BMKReverseGeoCodeOption *option = [ [BMKReverseGeoCodeOption al loc] init] ;option.reverseGeoPoint= userLocation. location.coordinate;

BOOLflag = [_geocodesearch reverseGeoCode:option];if (flag) {

}

//更新位置之后必须停止定位

[_locService stopUserLocationService];

}

-(void)mapView:(BMKMapView*)mapViewregionDidChangeAnimated:(BOOL)animated{

NSLog(@"地图拖劢");

[UIViewanimateWithDuration:0.30animations:^{self. loactionView.centerY-=8;

} completion:^(BOOL finished) {self. loactionView.centerY+=8;

}] ;

CGPoint touchPoint = self.mapView.center;

CLLocationCoordinate2D touchMapCoordinate =

[self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];//这里touchMapCoordinate就是该点的经纬度了

NSLog(@"touching%f,%f",touchMapCoordinate. latitude,touchMapCoordinate. longitude);

//选择的上传地址self.selectedCoordinate = touchMapCoordinate;

BMKReverseGeoCodeOption *option = [ [BMKReverseGeoCodeOption al loc] init] ;option.reverseGeoPoint= touchMapCoordinate;

BOOLflag = [_geocodesearch reverseGeoCode:option];if (flag) {

}

}

#pragma mark---获取反编码的数据---

-(void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcherresult:(BMKReverseGeoCodeResult *)resulterrorCode:(BMKSearchErrorCode)error{

BMKAddressComponent *component=[ [BMKAddressComponental loc]init] ;component=result.addressDetai l;

[self.dataA removeAl lObjects];for (int i =0; i< result.poiList.count; i++) {

BMKPoiInfo*info = result.poiList[i];

FTBMKPoiInfo*ftInfo=[[FTBMKPoiInfo al loc]init];ftInfo.address = info.address;ftInfo.seleced =NO;

if (i == 0) {ftInfo.seleced =YES;self.selectAddress = ftInfo.address;

}

[self.dataA addObject:ftInfo] ;

}

[self.tableview reloadData];

}

#pragma mark---定位的方法--

- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation

{

[_mapView updateLocationData:userLocation];

// NSLog(@"heading is%@",userLocation.heading);

}

-(BMKMapView*)mapView{if (!_mapView) {

_mapView=[ [BMKMapViewal loc] initWithFrame:CGRectMake(0,NAVH,Device_Width, 350)] ;

_mapView.zoomLevel = 18;

_mapView.minZoomLevel = 3;

_mapView.maxZoomLevel = 21;

// BMKLocationViewDisplayParam*displayParam=

[ [BMKLocationViewDisplayParam al loc] init] ;

// displayParam. isRotateAngleVal id = true;//跟随态旋转角度是否生效// displayParam. isAccuracyCircleShow= false;//精度圈是否显示// displayParam. locationViewOffsetX= 0;//定位偏移量(经度)

// displayParam. locationViewOffsetY= 0;//定位偏移量纬度

// [_mapView updateLocationViewWithParam:displayParam];

}return_mapView;

}

-(NSInteger)tableView:(UITableView*)tableViewnumberOfRowsInSection:(NSInteger)section{returnself.dataA.count;

}

-(UITableViewCel l *)tableView:(UITableView*)tableViewcel lForRowAtIndexPath:(NSIndexPath *)indexPath{

FTPoiCel l *cel l =[tableViewdequeueReusableCel lWithIdentifier:@"cel l "forIndexPath: indexPath];if (!cel l) {cel l =[ [FTPoiCel l al loc] initWithStyle:UITableViewCel lStyleDefaultreuseIdentifier:@"cel l "];

}

FTBMKPoiInfo*info = self.dataA[indexPath.row] ;cel l. info= info;returncel l ;

}

-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath

*)indexPath{

[tableView deselectRowAtIndexPath: indexPath animated:YES] ;

FTBMKPoiInfo*info = self.dataA[indexPath.row] ;self.selectAddress = info.address;

[self.dataAenumerateObjectsUsingBlock:^(FTBMKPoiInfo*obj,NSUInteger idx,BOOL *_Nonnul l stop) {i f (o bj == info) {obj.seleced =YES;

}else{obj.seleced =NO;

}

[self.tableviewreloadData] ;

}] ;if (self.selectBlock) {self.selectBlock(self.selectAddress,self.selectedCoordinate);

[self.navigationControl ler popViewControl lerAnimated:YES];

}

}

-(UITableView*)tableview{if (!_tableview) {

_tableview=[ [UITableViewal loc]initWithFrame:CGRectMake(0,self.mapView.bottom,Device_Width,Device_Height - self.mapView.bottom)style:UITableViewStylePlain];

_tableview.delegate = self;

_tableview.dataSource = self;

_tableview.showsVerticalScrol lIndicator= NO;

_tableview.showsHorizontalScrol lIndicator= NO;

_tableview.tableFooterView= [UIView new];

_tableview.rowHeight= 44;

[_tableview registerNib: [UINib nibWithNibName:@"FTPoiCel l "bundle:ni l]forCel lReuseIdentifier:@"cel l "] ;

// [_tableview registerClass:[UITableViewCel l class] forCel lReuseIdentifier:@"cel l "];}return_tableview;

}

-(NSMutableArray*)dataA{i f (!_d a ta A) {

_dataA=[NSMutableArrayarray];

}return_dataA;

}

-(UIImageView*)loactionView{if (!_loactionView) {

_loactionView=[[UIImageViewal loc] initWithImage: [UIImageimageNamed:@"ditu_red"]] ;

_loactionView.center = CGPointMake(self.mapView.width/2,self.mapView.height/2);

}return_loactionView;

}

-(LxButton *)poiBackBtn{if (!_poiBackBtn) {

_poiBackBtn =[LxButton LXButtonWithTitle:ni l titleFont:ni l Image:ni lbackgroundImage:ni l backgroundColor:[UIColorwhiteColor] titleColor:ni lframe:CGRectMake(Device_Width - 75, self.mapView.height - 75, 50, 50)];

[_poiBackBtn setFTCornerdious:25] ;

UIImageView*imageView=[[UIImageViewal loc] initWithImage:[UIImageimageNamed:@"poi_back"] ];imageView.center = CGPointMake(25,25);

[_poiBackBtnaddSubview: imageView] ;

}return_poiBackBtn;

}

@end

HaBangNet(6.95美元/月)美国vps 5TB流量/德国vps 香港双向CN2 GIA VPS

HaBangNet支持支付宝和微信支付,只是价格偏贵,之前国内用户并不多。这次HaBangNet推出三个特价套餐,其中美国机房和德国机房价格也还可以,但是香港机房虽然是双向CN2 GIA线路,但是还是贵的惊人,需要美国和德国机房的可以参考下。HaBangNet是一家成立于2014年的香港IDC商家,中文译名:哈邦网络公司,主营中国香港、新加坡、澳大利亚、荷兰、美国、德国机房的虚拟主机、vps、专用...

RAKsmart美国VPS上市,活动期间5折抢购仅$30,$1.99/月

RAKsmart机房将于7月1日~7月31日推出“年中大促”活动,多重惊喜供您选择;爆款I3-2120仅30美金秒杀、V4新品上市,活动期间5折抢购、爆款产品持续热卖、洛杉矶+硅谷+香港+日本站群恢复销售、G口不限流量产品超低价热卖。美国VPS、日本VPS及香港VPS享全场7折优惠;爆款VPS $ 1.99/月限量秒杀,10台/天,售完即止, VPS 7折优惠码:VPS-TP-disRAKsmar...

六一云互联(41元)美国(24元)/香港/湖北/免费CDN/免费VPS

六一云互联六一云互联为西安六一网络科技有限公司的旗下产品。是一个正规持有IDC/ISP/CDN的国内公司,成立于2018年,主要销售海外高防高速大带宽云服务器/CDN,并以高质量.稳定性.售后相应快.支持退款等特点受很多用户的支持!近期公司也推出了很多给力的抽奖和折扣活动如:新用户免费抽奖,最大可获得500元,湖北新购六折续费八折折上折,全场八折等等最新活动:1.湖北100G高防:新购六折续费八折...

反百度为你推荐
浏览器哪个好什么浏览器最好用?集成显卡和独立显卡哪个好独立显卡和集成显卡哪个更好些法兰绒和珊瑚绒哪个好法兰绒和珊瑚绒睡衣哪个好?车险哪个好车险平安和人保哪个好?都有什么优点和缺点?网络机顶盒哪个好什么牌子的网络机顶盒最好美国国际东西方大学明尼苏达大学(是莫瑞斯分校)和美国东北大学 应该去哪一个 是这个方面的专家回答啊!有偏见性的不要说!qq空间登录不上qq空间登不上去360云存储360网盘目前最大空间是多少强生月抛第一次戴隐形眼镜月抛的好不好?强生月抛的怎样啊哪个快递最便宜快递那种便宜 20公斤寄什么快递便宜
国外网站空间 根域名服务器 山东vps 赵容 便宜服务器 日志分析软件 dd444 中国电信测网速 美国堪萨斯 息壤代理 微软服务器操作系统 申请免费空间和域名 带宽租赁 什么是web服务器 工信部网站备案查询 防cc攻击 深圳域名 中国联通宽带测速 国内空间 阿里云邮箱申请 更多