IOS Baidu Map Get current location

Source: Internet
Author: User

////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

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.