iOS Map Integration example: Baidu Map poi Search

Source: Internet
Author: User
Tags radar

First, integrated Baidu map (fool tutorial, to the site description document, here are listed a few major steps)

1, Login http://lbsyun.baidu.com Baidu Map developer platform, access to the SDK and integration documentation.

2, Baidu Map can provide some of the services

(1) Map: Provide map display and map operation function;

(2) POI search: Support peripheral Search, regional search and intra-city point of interest retrieval;

(3) Geocoding: Provide the interface between latitude and longitude and the conversion of address information;

(4) Line planning: Support bus, driving, walking, riding, four ways of route planning;

(5) Overlay layer: Support to add overlay on the map (callout, geometry, heat force diagram, topographic map layer, etc.), to display more abundant lbs information;

(6) Positioning: Get the current position information and display on the map (support normal, follow, compass three modes);

(7) Offline Map: Use offline map to save user traffic and provide better map display effect;

(8) Switch Baidu Map: Using the SDK interface, directly on the local Baidu map client or WebApp, to achieve map function;

(9) Peripheral radar: The use of peripheral radar function, developers can be in the app low-cost, fast to find the surrounding use the same app user location function;

LBS Cloud Search: Support to query the data stored in the LBS cloud;

(11) Tile layer: Support to add own tile data on the map.

(12) Featured features: Provide short-string sharing, place details search, hot force and other features to help developers build more powerful applications;

2, create the application, get Appkey (key)

(1) You need to get key as a developer

(2) Note binding to bundle identifier

3. Precautions before configuring integration

(1) Strict reference documents!

(2) Several points of attention

<1> iOS9.0, to configure ATS in Info.plist

<2> in Info.plist Configure the whitelist of Baidu maps application (support to open Baidu map in its own application)

<3> Manage the life cycle of the map (manually empty the proxy)

<4> Add a reminder to get a location authorization in Info.plist

nslocationwheninuseusagedescription, allowing the GPS description to be used in the foreground

nslocationalwaysusagedescription, allow permanent use of GPS description

4. Configure the development environment

(1) Add Baidu's static library (. Framework)

(2) Import a large stack of system libraries

(3) Add Map package (Mapapi.bundle resource file)

(4) Introduction of all Header files

5. Initialize the map

(1) Initialize Bmkmapmanager

(2) Create Bmkmapview

6. Basic Map

(1) See the documentation! Http://lbsyun.baidu.com/index.php?title=iossdk/guide/basicmap

(2) Understanding of some functions

<1> map types: Normal vector maps, satellite maps, and blank maps (save traffic)

<2> Open a live traffic layer

<3> Thermal Map

<4> gestures, map controls, subscripts, polylines (shading of geometry)

<5> Set the map display range

<6>, etc...

Second, Baidu map poi Search

#import "ViewController.h" @interface Viewcontroller () <BMKMapViewDelegate,BMKPoiSearchDelegate> @property ( Nonatomic,weak) Bmkmapview * mapview; @property (nonatomic,weak) Uitextfield * TF; @property (Nonatomic,strong)        Bmkpoisearch * poisearch; @end @implementation viewcontroller-(void) viewdidload {[Super viewdidload]; Set map bmkmapview* Mapview = [[Bmkmapview alloc]initwithframe:cgrectmake (0, 0, [UIScreen mainscreen].bounds.size.width    , [UIScreen mainscreen].bounds.size.height)];    Self.mapview = Mapview;            [Self.view Addsubview:mapview];    Set Start lookup button and input text box UIButton * btn = [[UIButton alloc]initwithframe:cgrectmake (30, 30, 100, 30)];    [Btn settitle:@ "start looking for" forstate:uicontrolstatenormal];    [Btn addtarget:self Action: @selector (Btnclick:) forcontrolevents:uicontroleventtouchupinside];    [Btn Setbackgroundcolor:[uicolor Orangecolor];        [Self.view ADDSUBVIEW:BTN];    Uitextfield * tf = [[Uitextfield alloc]initwithframe:cgrectmake (150, 30, 100, 30)]; Self.tf= TF;    Tf.backgroundcolor = [Uicolor Orangecolor];            [Self.view ADDSUBVIEW:TF];    Instance POI retrieves the retrieved object and sets the proxy self.poisearch = [[Bmkpoisearch alloc]init];    Self.poisearch.delegate = self;     }-(void) Btnclick:(UIButton *) btn{//Retrieve parameters Bmkcitysearchoption *citysearchoption = [[Bmkcitysearchoption alloc]init]; Citysearchoption.pageindex = 0; Current page citysearchoption.pagecapacity = 20; Number per page citysearchoption.city= @ "Beijing"; City Citysearchoption.keyword = Self.tf.text;    Keyword Hotel//According to the retrieval parameters, and return the identification of the results of the search BOOL flag = [_poisearch poisearchincity:citysearchoption];    if (flag) {NSLog (@ "in-City search sent successfully");    } else {NSLog (@ "in the city failed to retrieve the send"); }} #pragma mark implement bmksearchdelegate-(void) Ongetpoiresult: (Bmkpoisearch *) Searcher Result: (bmkpoiresult*) Result ErrorCode: (bmksearcherrorcode) error{//Clears all annotation nsarray* array = [Nsarray arraywitharray:_mapview in the screen.    Annotations];    [_mapview Removeannotations:array]; Correct if(Error = = Bmk_search_no_error)        {Nsmutablearray *annotations = [Nsmutablearray array]; Iterates over the returned query results for (int i = 0; i < Result.poiInfoList.count; i++) {bmkpoiinfo* poi = [Result.poiinfolis            T OBJECTATINDEX:I];            bmkpointannotation* item = [[Bmkpointannotation alloc]init];            Item.coordinate = poi.pt;            Item.title = Poi.name;        [Annotations Addobject:item];        }//Add a PIN model to the map [_mapview addannotations:annotations];                    [_mapview showannotations:annotations Animated:yes];    } else if (Error = = bmk_search_ambiguous_roure_addr) {NSLog (@ "starting point ambiguous");    } else {//judgment of various cases ... }} #pragma mark implement bmkmapviewdelegate/** * generates the corresponding view * @param mapview map view * @param annotation The specified callout * @re Turn generated callout view */-(Bmkannotationview *) Mapview: (Bmkmapview *) View viewforannotation: (ID <BMKAnnotation>) annotation{//Generate Reuse indicator identifier NSString *ANNOTATIONVIEWID = @ "Xidanmark"; Check if there is a reused cache bmkannotationview* Annotationview = [view Dequeuereusableannotationviewwithidentifier:annotationviewid        ]; The cache does not, itself constructs one, the general first add annotation code will run to here if (Annotationview = = nil) {Annotationview = [[Bmkpinannotationview all]        OC] Initwithannotation:annotation Reuseidentifier:annotationviewid];        ((bmkpinannotationview*) annotationview). Pincolor = bmkpinannotationcolorred;    Sets the effect (annotation) ((bmkpinannotationview*) Annotationview) that the heavy sky falls off. Animatesdrop = YES;    }//Set position Annotationview.centeroffset = Cgpointmake (0,-(annotationView.frame.size.height * 0.5));    annotationview.annotation = annotation;    Click Eject Bubble, Pop bubble premise annotation must implement Title property Annotationview.canshowcallout = YES;        Set whether you can drag annotationview.draggable = NO; return Annotationview;}    -(void) Viewwillappear: (BOOL) animated{[_mapview viewwillappear]; _mapview.delegate = self; Remember to place nil when not in use, otherwise affect the memory release}-(void) Viewwilldisappear: (BOOL)animated{[_mapview viewwilldisappear]; _mapview.delegate = nil; When not in use, place nil} @end

iOS Map Integration example: Baidu Map poi Search

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.