你的位置:首页 > 操作系统

[操作系统]iOS第三方地图-百度地图中心点定位


使用百度地图定位后,滑动地图,使用反编码确定地图中心店的位置信息

//// MapControl.m// quyizu//// Created by apple on 15/9/2.// Copyright (c) 2015年 waste. All rights reserved.////使用百度地图定位,poi搜索,地理编码功能#import "MapControl.h"#import "WJBaiduMapTools.h"@interface MapControl ()<BMKPoiSearchDelegate,BMKMapViewDelegate,BMKGeoCodeSearchDelegate,BMKLocationServiceDelegate>{  BMKMapView *_mapView;        //地图  BMKPoiSearch *_poisearch;      //poi搜索  BMKGeoCodeSearch *_geocodesearch;  //geo搜索服务  CGFloat _longitude;   //经度  CGFloat _latitude;   //纬度  UILabel *_labelShow;   //信息显示  NSInteger _index;    //判断次数  BMKLocationService* _locService;  UIImageView *_viewCenterBG;}@end@implementation MapControl- (instancetype)init{  self = [super init];  if (self) {    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(rightItemPressed)];    self.navigationItem.rightBarButtonItem = rightItem;  }  return self;}- (void)rightItemPressed {  [self.navigationController popViewControllerAnimated:YES];  if ([_delegate respondsToSelector:@selector(mapControlDelegate:isSchool:)]) {    [_delegate mapControlDelegate:_labelShow.text isSchool:_isSchool];  }}- (void)viewWillAppear:(BOOL)animated {  [super viewWillAppear:animated];   _mapView.delegate = self;  _geocodesearch.delegate = self;  _locService.delegate = self;}-(void)viewWillDisappear:(BOOL)animated{  _mapView.delegate = nil; // 不用时,置nil  _poisearch.delegate = nil; // 不用时,置nil  _geocodesearch.delegate = nil;  _locService.delegate = nil;}- (void)dealloc {  if (_geocodesearch != nil) {    _geocodesearch = nil;  }  if (_mapView) {    _mapView = nil;  }}- (void)viewDidLoad {  [super viewDidLoad];  if (_isSchool) {    [self addnavigationTitle:@"上学方便"];  }else {    [self addnavigationTitle:@"工作方便"];  }  _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];  [_mapView setZoomLevel:17];  [self.view addSubview:_mapView];  _geocodesearch = [[BMKGeoCodeSearch alloc]init];  _locService = [[BMKLocationService alloc]init];  [_locService startUserLocationService];  [self initCenterView];}- (void)initCenterView {  UIView *viewBG = [[UIView alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth, 60)];  [self.view addSubview:viewBG];    UIView *viewBGalpha = [[UIView alloc]initWithFrame:viewBG.bounds];  viewBGalpha.backgroundColor = [UIColor blackColor];  viewBGalpha.alpha = 0.4;  [viewBG addSubview:viewBGalpha];    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, ScreenWidth-30, 60)];  label.textAlignment = NSTextAlignmentCenter;  label.text = @"地图显示";  label.numberOfLines = 2;  label.font = [UIFont systemFontOfSize:14];  label.textColor = [UIColor whiteColor];  [viewBG addSubview:label];  _labelShow = label;    UIImageView *viewCenterBG = [[UIImageView alloc]init];  viewCenterBG.image = [UIImage imageNamed:@"map_iconBG"];  viewCenterBG.center = CGPointMake(ScreenWidth/2, ScreenHeight/2);  viewCenterBG.bounds = CGRectMake(0, 0, 50, 50);  viewCenterBG.alpha = 0.5;  _viewCenterBG= viewCenterBG;  [self.view addSubview:viewCenterBG];    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(timerPressed) userInfo:nil repeats:YES];    UIView *view = [[UIView alloc]init];  view.center = CGPointMake(ScreenWidth/2, ScreenHeight/2);  view.bounds = CGRectMake(0, 0, 15, 15);  view.layer.cornerRadius = 7.5;  view.layer.borderWidth = 1;  view.layer.borderColor = [UIColor whiteColor].CGColor;  view.layer.masksToBounds = YES;  view.backgroundColor = [UIColor colorWithHexString:@"69c9fa"];  [self.view addSubview:view];}- (void)timerPressed {  [UIView animateWithDuration:2 animations:^{    _viewCenterBG.bounds = CGRectMake(0, 0, 100, 100);    _viewCenterBG.alpha = 0.1;  } completion:^(BOOL finished) {    [UIView animateWithDuration:2 animations:^{      _viewCenterBG.bounds = CGRectMake(0, 0, 50, 50);      _viewCenterBG.alpha = 0.5;    }];  }];}#pragma mark - 根据经纬度搜索- (void)reverseGeoPointSearchlongitude:(CGFloat )longitude latitude:(CGFloat)latitude{    CLLocationCoordinate2D pt = (CLLocationCoordinate2D){0, 0};    pt = (CLLocationCoordinate2D){latitude, longitude};  BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init];  reverseGeocodeSearchOption.reverseGeoPoint = pt;  BOOL flag = [_geocodesearch reverseGeoCode:reverseGeocodeSearchOption];  if(flag)  {    NSLog(@"反geo检索发送成功");  }  else  {    NSLog(@"反geo检索发送失败");  }}#pragma mark - BMKMapViewDelegate//地图改变完成调用这个接口- (void)mapView:(BMKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {    if (_longitude == mapView.centerCoordinate.longitude &&_latitude == mapView.centerCoordinate.latitude) {      }else {    if (_index !=0) {      [self reverseGeoPointSearchlongitude:mapView.centerCoordinate.longitude latitude:mapView.centerCoordinate.latitude];      _longitude = mapView.centerCoordinate.longitude;      _latitude = mapView.centerCoordinate.latitude;    }  }  NSLog(@"%f,%f",mapView.centerCoordinate.longitude,mapView.centerCoordinate.latitude);}#pragma mark - BMKGeoCodeSearchDelegate// *返回反地理编码搜索结果- (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error {  if (error == 0) {    BMKPointAnnotation* item = [[BMKPointAnnotation alloc]init];    item.coordinate = result.location;    item.title = result.address;    if (_index == 0) {      _mapView.centerCoordinate = result.location;      _index ++;    }    NSString* titleStr;    NSString* showmeg;    titleStr = @"反向地理编码";    showmeg = [NSString stringWithFormat:@"%@",item.title];    _labelShow.text = showmeg;  }}#pragma mark - BMKLocationServiceDelegate- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation {  [_locService stopUserLocationService];  [self reverseGeoPointSearchlongitude:userLocation.location.coordinate.longitude latitude:userLocation.location.coordinate.latitude];}@end

湖南旅游攻略大全湖南旅游路线推荐湖南自驾游攻略湖南旅游线路大全什么时候去湖南旅游最好江西婺源—中国最美的乡村 金秋峨眉,红叶温泉季节正式拉开序幕 丽江:23个景区门票降价 威尼斯的水上浪漫之地 邹平汽车站到鹤伴山有车吗?邹平到鹤伴山怎么坐车? 周村到鹤伴山怎么走?周村到邹平鹤伴山自驾车路线? 邹平县城到鹤伴山坐几路公交车?邹平县城到鹤伴山森林公园有直达车吗? 张店到鹤伴山怎么走?张店到邹平鹤伴山自驾车路线? 峨眉山记载 黄冈著名小吃介绍 (组图)柳州餐饮介绍 【云南美食】----普洱饮食特色介绍 深圳年货会什么时候开始? 春节想在罗湖附近看电影,有什么好推荐? 深圳北站到韶关的高铁一共有多少趟车? 春节深圳哪里比较热闹? 08055C104KAT2A Datasheet 08055C104KAT2A Datasheet 08053C154KAT2A Datasheet 08053C154KAT2A Datasheet 0805YC224KAT2A Datasheet 0805YC224KAT2A Datasheet 龙岩土楼 龙岩土楼 龙岩土楼 沂蒙山旅游 沂蒙山旅游 沂蒙山旅游 攻略网 攻略网 攻略网