Use Baidu Map to locate, slide the map, use anti-coding to determine the location 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 location, poi search, geocoding function#import "MapControl.h"#import "WJBaiduMapTools.h"@interfaceMapcontrol () <bmkpoisearchdelegate,bmkmapviewdelegate,bmkgeocodesearchdelegate,bmklocationservicedelegate >{Bmkmapview*_mapview;//MapBmkpoisearch *_poisearch;//POI SearchBmkgeocodesearch *_geocodesearch;//Geo Search ServiceCGFloat _longitude;//LongitudeCGFloat _latitude;//LatitudeUILabel *_labelshow;//Information DisplayNsinteger _index;//Number of judgementsbmklocationservice*_locservice; Uiimageview*_VIEWCENTERBG;}@end@implementationMapcontrol-(instancetype) init{ Self=[Super Init]; if(self) {Uibarbuttonitem*rightitem = [[Uibarbuttonitem alloc]initwithtitle:@"Determine"Style:uibarbuttonitemstyleplain target:self Action: @selector (rightitempressed)]; Self.navigationItem.rightBarButtonItem=Rightitem; } returnSelf ;}- (void) rightitempressed {[Self.navigationcontroller popviewcontrolleranimated:yes]; if([_delegate respondstoselector: @selector (mapcontroldelegate:isschool:)]) {[_delegate Mapcontroldelegate:_labe Lshow.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, place nil_poisearch.Delegate= nil;//when not in use, place 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:@"easy to go to school"]; }Else{[Self addnavigationtitle:@"Easy to work"]; } _mapview= [[Bmkmapview alloc]initwithframe:cgrectmake (0,0, ScreenWidth, ScreenHeight)]; [_mapview setzoomlevel: -]; [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, -, ScreenWidth, -)]; [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 ( the,0, screenwidth- -, -)]; Label.textalignment=Nstextalignmentcenter; Label.text=@"Map Display"; Label.numberoflines=2; Label.font= [Uifont systemfontofsize: -]; 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, -, -); Viewcenterbg.alpha=0.5; _VIEWCENTERBG=VIEWCENTERBG; [Self.view ADDSUBVIEW:VIEWCENTERBG]; [Nstimer scheduledtimerwithtimeinterval:2target: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, the, the); 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:2animations:^{_viewcenterbg.bounds= CGRectMake (0,0, -, -); _viewcenterbg.alpha=0.1; } Completion:^(BOOL finished) {[UIView animatewithduration:2animations:^{_viewcenterbg.bounds= CGRectMake (0,0, -, -); _viewcenterbg.alpha=0.5; }]; }];}#pragmaMark-Search by latitude and longitude-(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 (@"anti-geo retrieval sent successfully"); } Else{NSLog (@"anti-geo retrieval send failed"); }}#pragmaMark-bmkmapviewdelegate//Map Change complete Call this interface- (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.centerCoordina Te.latitude]; _longitude=MapView.centerCoordinate.longitude; _latitude=MapView.centerCoordinate.latitude; }} NSLog (@"%f,%f", mapview.centercoordinate.longitude,mapview.centercoordinate.latitude);}#pragmaMark-bmkgeocodesearchdelegate//* Return to Anti-geocoding search results- (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=@"Reverse geocoding"; Showmeg= [NSString stringWithFormat:@"%@", Item.title]; _labelshow.text=Showmeg; }}#pragmamark-bmklocationservicedelegate-(void) Didupdatebmkuserlocation: (Bmkuserlocation *) userlocation {[_locservice stopuserlocationservice]; [Self reverseGeoPointSearchlongitude:userLocation.location.coordinate.longitude Latitude: UserLocation.location.coordinate.latitude];}@end
iOS third-party map-Baidu Map Center point location