Development of iOS based on lbs platform

Source: Internet
Author: User

LBS, the location Based services, is used for positioning, navigation and other functions, such as maps applications, ordering takeout, and other apps that need this functionality.

Here I am using the gold-based LBS open platform, address: http://lbs.amap.com/

Enter the site, register and authenticate as a developer, and then request a key for each of your apps, where the security Code (bundle Identifier) switches from Xcode to the General tab to view Bundle Identifier.

Using a third-party service, we can use the automatic configuration, which will be used to cocoapods. Cocoapods is a tool to help us manage third-party dependent libraries. It solves the dependencies between libraries and libraries, downloads the source code of the library, and connects these third-party libraries to our project by creating a Xcode workspace for us to develop and use. The purpose of using cocoapods is to enable us to automate, centralize, and intuitively manage third-party open source libraries.

To install the Cocoapods tutorial:

Gem Sources-lgem sources--remove https://rubygems.org/gem sources-a http://ruby.taobao.org/gem sources-lsudo gem Insta ll Cocoapods

Create Podfile:

Cd/projecttouch Podfile

Edit Podfile File:

SOURCE ' Https://github.com/CocoaPods/Specs.git ' Platform:ios, ' 7.0 ' #手机系统 #pod ' amap3dmap ' #3D地图SDKpod ' Amap2dmap ' # The Map SDK (3D cannot be used simultaneously) pod ' amapsearch ' #搜索服务SDK以下是额外补充 #platform:ios  #pod ' reachability ',  ' ~> 3.0.0 '  # Pod ' Sbjson ', ' ~> 4.0.0 '  #platform: iOS, ' 7.0 '  #pod ' afnetworking ', ' ~> 2.0 '  

Then go to the project directory, enter the command pod install

Then open the project with the Cocoapods installed by opening the Xcworkspace file

Here is the core code of my controller.m, for reference only:

#import "ViewController.h"#import<MAMapKit/MAMapKit.h>#import<AMapSearchKit/AMapSearchAPI.h>#defineAPIKey @ "You apply for key"@interfaceViewcontroller () <MAMapViewDelegate,AMapSearchDelegate>{Mamapview*_mapview; Amapsearchapi*_search; Cllocation*_currentlocation; UIButton*_locationbutton;}@end@implementationViewcontroller- (void) initcontrols{_locationbutton=[UIButton Buttonwithtype:uibuttontypecustom]; _locationbutton.frame= CGRectMake ( -, Cgrectgetheight (_mapview.bounds)- the, +, +); _locationbutton.autoresizingmask= Uiviewautoresizingflexiblerightmargin |Uiviewautoresizingflexibletopmargin; _locationbutton.backgroundcolor=[Uicolor Whitecolor]; _locationbutton.layer.cornerradius=5;    [_locationbutton addtarget:self Action: @selector (Locateaction) forcontrolevents:uicontroleventtouchupinside]; [_locationbutton setimage:[uiimage imagenamed:@"Location_no"] Forstate:uicontrolstatenormal];    [_mapview Addsubview:_locationbutton]; }//Search Service- (void) initsearch{_search=[[Amapsearchapi Alloc]initwithsearchkey:apikey delegate:self];}//Modifying the user targeting mode- (void) locateaction{if(_mapview.usertrackingmode! =Mausertrackingmodefollow)    {[_mapview setusertrackingmode:mausertrackingmodefollow animated:yes]; }}//Geocoding Search Requests- (void) regeoaction{if(_currentlocation) {amapregeocodesearchrequest*request =[[Amapregeocodesearchrequest alloc]init]; Request.location=[Amapgeopoint locationwithlatitude:_currentlocation.coordinate.latitude longitude:_        CurrentLocation.coordinate.longitude];    [_search Amapgeocodesearch:request]; }}- (void) SearchRequest: (IDRequest Didfailwitherror: (Nserror *) error{NSLog (@"Request:%@, error:%@", Request,error);}- (void) Onregeocodesearchdone: (amapgeocodesearchrequest *) Request response: (Amapregeocodesearchresponse *) response{NSLog (@"Response:%@", response); NSString*title =response.regeocode.addressComponent.city; if(Title.length = =0) {title=response.regeocode.addressComponent.province; } _mapview.userlocation.title=title; _mapview.userlocation.subtitle=response.regeocode.formattedAddress;}//User Agent Methods- (void) Mapview: (Mamapview *) Mapview Didchangeusertrackingmode: (mausertrackingmode) mode animated: (BOOL) animated{//Modify the Position button state    if(Mode = =Mausertrackingmodenone) {[_locationbutton setimage:[uiimage imagenamed:@"Location_no"] Forstate:uicontrolstatenormal]; }    Else{[_locationbutton setimage:[uiimage imagenamed:@"Location_yes"] Forstate:uicontrolstatenormal]; }}//Record your current location- (void) Mapview: (Mamapview *) Mapview didupdateuserlocation: (mauserlocation *) userlocation updatinglocation: (BOOL) updatinglocation{NSLog (@"userlocation:%@", userlocation.location); _currentlocation=[userlocation.location copy]; }- (void) Mapview: (Mamapview *) Mapview Didselectannotationview: (Maannotationview *) view{//Inverse geocoding Query when locating annotation is selected    if([View.annotation Iskindofclass:[mauserlocationclass] ]) {[Self regeoaction]; }}//Initialize Map- (void) initmapview{[mamapservices Sharedservices].apikey=APIKey; _mapview= [[Mamapview alloc]initwithframe:cgrectmake (0,0, Cgrectgetwidth (self.view.bounds), Cgrectgetheight (Self.view.bounds))]; //set the location of the proxy and two attachments for a map_mapview.Delegate=Self ; _mapview.compassorigin= Cgpointmake (_mapview.compassorigin.x, A); _mapview.scaleorigin= Cgpointmake (_mapview.scaleorigin.x, A);    [Self.view Addsubview:_mapview]; //Open User Targeting_mapview.showsuserlocation =YES; }- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib.[self initmapview];    [Self initsearch]; [Self initcontrols];}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}@end

Operation Result:

If you have more API interfaces you want to implement, you can go to the High de lbs open platform to see the development documentation that can be further developed.

GitHub Address: Https://github.com/AbelSu131/HelloAmap

Development of iOS based on lbs platform

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.