iOS第三方地圖-百度地圖中心點定位,ios第三方

來源:互聯網
上載者:User

iOS第三方地圖-百度地圖中心點定位,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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.