定位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

趣米云(18元/月)香港三网CN2云服器低至;1核1G/30G系统盘+20G数据盘/10M带宽

趣米云怎么样?趣米云是创建于2021年的国人IDC商家,虽然刚刚成立,但站长早期为3家IDC提供技术服务,已从业2年之久,目前主要从事出售香港vps、香港独立服务器、香港站群服务器等,目前在售VPS线路有三网CN2、CN2 GIA,该公司旗下产品均采用KVM虚拟化架构。由于内存资源大部分已售,而IP大量闲置,因此我们本月新增1c1g优惠套餐。点击进入:趣米云官方网站地址香港三网CN2云服务器机型活...

Digital-VM:服务器,$80/月;挪威/丹麦英国/Digital-VM:日本/新加坡/digital-vm:日本VPS仅$2.4/月

digital-vm怎么样?digital-vm在今年1月份就新增了日本、新加坡独立服务器业务,但是不知为何,期间终止了销售日本服务器和新加坡服务器,今天无意中在webhostingtalk论坛看到Digital-VM在发日本和新加坡独立服务器销售信息。服务器硬件是 Supermicro、采用最新一代 Intel CPU、DDR4 RAM 和 Enterprise Samsung SSD内存,默认...

pigyun25元/月,香港云服务器仅起;韩国云服务器,美国CUVIP

pigyun怎么样?PIGYun成立于2019年,2021是PIGYun为用户提供稳定服务的第三年,期待我们携手共进、互利共赢。PIGYun为您提供:香港CN2线路、韩国CN2线路、美西CUVIP-9929线路优质IaaS服务。月付另有通用循环优惠码:PIGYun,获取8折循环优惠(永久有效)。目前,PIGYun提供的香港cn2云服务器仅29元/月起;韩国cn2云服务器仅22元/月起;美国CUVI...

反百度为你推荐
马云将从软银董事会辞职马云为什么辞职p图软件哪个好用什么p图软件好用?不是p人照片的那种软件浏览器哪个好什么浏览器最好?锦天城和君合哪个好和君咨询(王明夫为董事长)到底怎么样?有人说很好,空间大;也有人说像待遇差。麒麟990和骁龙865哪个好海思麒麟990和骁龙710哪个好?视频剪辑软件哪个好后期视频剪辑什么软件最专业?朱祁钰和朱祁镇哪个好朱高炽是不是被朱瞻基谋杀的?朱祁镇和朱祁钰谁更好尼康和佳能单反哪个好尼康和佳能哪个好网络机顶盒哪个好现在网络机顶盒哪个牌子好?yy空间登录yy空间怎么上传照片?
虚拟主机租用 域名备案中心 如何查询域名备案号 linuxapache虚拟主机 美国主机排名 新秒杀 西安电信测速 美国主机推荐 pccw 华为网络硬盘 七夕快乐英文 傲盾官网 idc查询 linux使用教程 超级服务器 华为云服务登录 vul 深圳域名 金主 免费稳定空间 更多