IOS third-party map-Baidu map center location, ios third-party

Source: Internet
Author: User

IOS third-party map-Baidu map center location, ios third-party

After positioning using Baidu map, slide the map and use anti-code to determine the location information of the map center store

//// MapControl. m // quyizu /// Created by apple on 15/9/2. // Copyright (c) 2015 waste. all rights reserved. //// use Baidu map positioning, poi search, and geocode # import "MapControl. h "# import" WJBaiduMapTools. h "@ interface MapControl () <outputs, BMKMapViewDelegate, BMKGeoCodeSearchDelegate, outputs> {BMKMapView * _ mapView; // map BMKPoiSearch * _ poisearch; // search for BMKGeoCodeSearch * _ geocodesearch; // geo Search Service CGFloat _ longpolling; // longitude CGFloat _ latitude; // latitude UILabel * _ labelShow; // NSInteger _ index is displayed; // Number of BMKLocationService * _ locService; UIImageView * _ viewCenterBG;} @ end @ implementation MapControl-(instancetype) init {self = [super init]; if (self) {UIBarButtonItem * rightItem = [[UIBarButtonItem alloc] initWithTitle: @ "OK" style: UIBarButtonItemStylePlain target: self action: @ selector (rightItemPres Sed)]; 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; // when not in use, set nil _ earch. delegate = nil; // when not in use, set 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] I Nit]; _ 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 = @ "Map Display"; label. numberOfLines = 2; label. font = [UIFont systemFontOfSize: 14]; label. textColor = [UIColor whiteColor]; [viewBG addSubview: label]; _ labelShow = label; UIImageView * viewCenterBG = [[UIImageView alloc] init]; vie WCenterBG. 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 al Loc] 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-search by latitude and longitude-(void) reversegeopointsearchlong.pdf :( CGFloat) long1_latitude :( CGFloat) latitude {CLLocationCoordinate2D pt = (CLLocation Coordinate2D) {0, 0}; pt = (longitude) {latitude, longpolling}; BMKReverseGeoCodeOption * reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc] init]; reverseGeocodeSearchOption. reverseGeoPoint = pt; BOOL flag = [_ geocodesearch reverseGeoCode: reverseGeocodeSearchOption]; if (flag) {NSLog (@ "anti-geo retrieval sent successfully ");} else {NSLog (@ "failed to send anti-geo search") ;}# pragma mark-BMKMapViewDelegate // call this interface when the map changes -(Void) mapView :( BMKMapView *) mapView regionDidChangeAnimated :( BOOL) animated {if (_ longpolling = mapView. centerCoordinate. longpolling & _ latitude = mapView. centerCoordinate. latitude) {} else {if (_ index! = 0) {[self reversegeopointsearchlongpolling: mapView. centerCoordinate. longpolling latitude: mapView. centerCoordinate. latitude]; _ longpolling = mapView. centerCoordinate. longpolling; _ latitude = mapView. centerCoordinate. latitude ;}} NSLog (@ "% f, % f", mapView. centerCoordinate. longpolling, mapView. centerCoordinate. latitude) ;}# pragma mark-BMKGeoCodeSearchDelegate // * returns the anti-geocode search result-(void) onGetReverseGeoCodeResult :( BMKGeoCodeSearch *) searcher result :( partial *) 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 = @ "reverse geocode"; showmeg = [NSString stringWithFormat: @ "% @", item. title]; _ labelShow. text = showmeg ;}# pragma mark-upload-(void) didUpdateBMKUserLocation :( BMKUserLocation *) userLocation {[_ locService stopUserLocationService]; [self reversegeopointsearchlongdistance: userLocation. location. coordinate. longpolling latitude: userLocation. location. coordinate. latitude] ;}@ end

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.