////VIEWCONTROLLER.M//Baidudemo////Created by Chocolate. On 15-3-2.//Copyright (c) 2015 Redasen. All rights reserved.//#import "ViewController.h"#import "BMapKit.h"@interfaceViewcontroller () <bmkgeocodesearchdelegate,bmkmapviewdelegate, bmklocationservicedelegate>@property (Strong, nonatomic) Bmkmapview*Mapview, @property (Strong, nonatomic) Bmkgeocodesearch*search; @property (strong, nonatomic) Bmklocationservice*Locservice;@end@implementationviewcontroller{bmkuserlocation*mylocation;}- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib._mapview =[[Bmkmapview alloc] initWithFrame:self.view.bounds]; [Self.view Addsubview:_mapview]; _search=[[Bmkgeocodesearch alloc]init]; //Initialize Bmklocationservice_locservice =[[Bmklocationservice alloc]init]; _locservice.Delegate=Self ; //Start Locationservice[_locservice startuserlocationservice];}-(void) Viewwillappear: (BOOL) animated{[_mapview viewwillappear]; _mapview.Delegate=Self ; _search.Delegate=Self ;}-(void) Viewdidappear: (BOOL) animated{[_mapview setshowsuserlocation:yes];}-(void) Viewwilldisappear: (BOOL) animated{[_mapview Setshowsuserlocation:no]; _mapview.Delegate=Nil; _search.Delegate=Nil;}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}#pragmaMark-bmklocationservicedelegate/** * This function is called when positioning is about to start*/- (void) willstartlocatinguser{}/** * This function is called when the location is stopped*/- (void) didstoplocatinguser{cllocationcoordinate2d pt= (cllocationcoordinate2d) {0,0}; PT=(cllocationcoordinate2d) {myLocation.location.coordinate.latitude, myLocation.location.coordinate.longitude} ; Bmkreversegeocodeoption*option =[[Bmkreversegeocodeoption alloc]init]; Option.reversegeopoint=pt; BOOL result=[_search reversegeocode:option]; if(Result) {NSLog (@"anti-geo retrieval sent successfully"); } Else{NSLog (@"anti-geo retrieval send failed"); }}/** * After the user orientation is updated, this function is called * @param userlocation New User Location*/- (void) Didupdateuserheading: (Bmkuserlocation *) userlocation{NSLog (@"heading is%@", userlocation.heading);}/** * This function is called when the user location is updated * @param userlocation new User Location*/- (void) Didupdatebmkuserlocation: (Bmkuserlocation *) userlocation{if(Userlocation! =Nil) {NSLog (@"Get Location Success"); Mylocation=userlocation; _mapview.showsuserlocation=NO; [_locservice Stopuserlocationservice]; } NSLog (@"didupdateuserlocation lat%f,long%f", userlocation.location.coordinate.latitude,userlocation.location.coordinate.longitude);}/** * This function is called when the location fails * @param error number*/- (void) Didfailtolocateuserwitherror: (Nserror *) error{}#pragmaMark-bmkgeocodesearchdelegate/** * Return address information search results * @param searcher Search Object * @param result search knot bmkgeocodesearch fruit * @param error number @see Bmksearcherrorcode */- (void) Ongetgeocoderesult: (Bmkgeocodesearch *) Searcher Result: (Bmkgeocoderesult *result ErrorCode: (Bmksearcherrorcode) error{}/** * Return to Anti-geocoding search results * @param searcher Search Object * @param result Search Result * @param error number @see Bmksearcherrorcode*/- (void) Ongetreversegeocoderesult: (Bmkgeocodesearch *) Searcher Result: (Bmkreversegeocoderesult *result ErrorCode: (bmksearcherrorcode) error{Uialertview*alert = [[Uialertview alloc]initwithtitle:@""Message:result.addressDelegate: Self Cancelbuttontitle:@"Close"Otherbuttontitles:nil, nil]; [Alert show];}@end
IOS Baidu Map Get current location