How the "Gold API" uses Mapkit to develop iOS maps for full English retrieval

Source: Internet
Author: User

The original: "Gold API" how to use Mapkit to develop a full English search of the iOS map

It is not difficult to make a full English map, but to make a full English data retrieval list, the Full English Information window, you have no choice. I'm telling you, I got a coup! Using iOS's Mapkit to showcase the global English basemap , combined with the English-Chinese search function of the high-German API, we can create the most abundant poi data in English with a full English-language map! Look, is it a natural?

--------------------------------------------------------------------------------------------------------------- ----------------

Here's how to get started with a pure English map, and help programmers connect with international apps!

First step: Apply key

apply for the key first : http://lbs.amap.com/console/key/

1. Fill in the application name

2. Binding Service Select iOS platform

3. Enter Bundle ID: switch xcode to the General tab to view bundle Identifier

4. Click to get key

The second step, the new map project

In Xcode, create a new single View application project and configure it.

In the German official website has the map configuration detailed explanation, here I not to say more. View: http://lbs.amap.com/api/ios-sdk/guide/mapview/

Step three, add Mkmapview

1, select the Build phases tag in Xcode, click the Link Binary with Libraries, then click the plus sign.

2. Search for Mapkitin the pop-up search box.

3. Select IOS 8.0-mapkit.framework, and then click Add .

Fourth step, apply for location permission

append in Info.plist Nslocationalwaysusagedescription or nslocationalwaysusagedescription field.

Nslocationwheninuseusagedescription indicates that the application can search for updated location information in the foreground; nslocationalwaysusagedescription indicates that the app can get updated location data in both foreground and background (suspend or terminated).

So I still suggest nslocationalwaysusagedescription this kind of convenient mode, haha.

1. In the engineeringSupporting FilesSelected inplistFile
2. Click the + sign to enter the fieldnslocationalwaysusagedescription3. Press ENTER to complete the Add field

Fifth Step, initialize Mapview

The German coordinate system is the domestic standard coordinate (GCJ-02, also called the Mars coordinate), the international generally uses the GPS coordinates (WGS-84), therefore most international application uses in China, needs coordinates transformation.

Fortunately, Apple's mapkit with the map of the gold,showuserlocation= yes, coordinates are already GCJ-02, can be used directly ~

(PS: It is not recommended to use the Cllocationmanager location management class, which returns coordinates that are GPS coordinates and must be converted in coordinates, very cumbersome.) )
//Apply for location permissions-  (void) initlocation {if(Nil = =_locationmanager) {_locationmanager=[[Cllocationmanager alloc] init]; }          if([[[[Uidevice Currentdevice] systemversion] Floatvalue] >=8.0) {[_locationmanager requestalwaysauthorization]; }  }
//Initialize Mapview- (void) initmapview{
//Construction Mkmapview_mapview= [[Mkmapview alloc] Initwithframe:cgrectmake (0, +, Cgrectgetwidth (self.view.bounds), Cgrectgetheight (Self.view.bounds))]; _mapview.Delegate=Self ; _mapview.showsuserlocation= YES;//Show positioning icon[_mapview Setusertrackingmode:mkusertrackingmodefollow];//Setting the positioning mode
//add Mapview to Subview[Self.view Addsubview:_mapview]; }

Sixth step, initialize AmapsearchapiConstructs the Amapsearchapi object, sets the search result language to Englishamapsearchlanguage_en。 This step is very important oh! Must be set to English, in order to skillfully let poi search, inverse geocoding and geocoding, input hints, etc., all become pure English Oh.
// Initialize AMAPSEARCHAPI  -  (void) initsearch  {       // construction amapsearchapi       = [ [Amapsearchapi alloc] Initwithsearchkey:apikey delegate:self];        = Amapsearchlanguage_en; // Set Language   }

Seventh step, write a search demo to see

Take a common poi search as an example, when searching English keywords, come out pure English search suggestions; The results are also shown in English.

/*POI Search. */-  (void) Searchpoiwithkey: (NSString *) key Adcode: (NSString *) Adcode {if(Key.length = =0)     {           return; }
//Construct Poi Search Object Amapplacesearchrequestamapplacesearchrequest*place =[[Amapplacesearchrequest alloc] init];
//Set KeywordsPlace.keywords=key; Place.requireextension= YES;//set to Yes to return information in detail, more than the cost of traffic if(Adcode.length >0) {place.city=@[adcode]; } //initiating a query[_search Amapplacesearch:place]; } //results displayed in callback- (void) Onplacesearchdone: (amapplacesearchrequest *) Request response: (Amapplacesearchresponse *) respons {if(Respons.pois.count = =0) { return; } Nsmutablearray*poiannotations =[Nsmutablearray ArrayWithCapacity:respons.pois.count]; [Respons.pois Enumerateobjectsusingblock:^ (Amappoi *obj, Nsuinteger idx, BOOL *stop) {[Poiannotations addobject:[[poiannotation alloc] initwithpoi:obj]]; }];
/*loads the results on the map as annotation.*/[_mapview addannotations:poiannotations];
/*If there is only one result, set it as the center point.*/ if(Poiannotations.count = =1) {_mapview.centercoordinate= [poiannotations[0] coordinate]; }
/*If there are multiple results, set the map to make all annotation visible.*/ Else{[_mapview showannotations:poiannotations animated:no]; } }

Finally, imagine you are a foreigner, to change your phone language to Chinese , at this time, the English basemap appears!

In fact, if you use the German iOS SDK, also has the English basemap, but must call the SDK ah, very troublesome. If you are looking for a foreigner in China, it's better to call iOS Mapkit directly.

If you want to develop an English-language map of Android, then it 's OK to use the Android SDK directly .

Finally, here is the full source download: Https://github.com/autonaviapi/HelloAmapForEnglish

Let's try it! ~ ~ really is a second international stylish bright ~ See again ~

--------------------------------------------------------------------------------------------------------------- ----------------

about why you should choose the Gold API:

1, the Apple Mapkit is originally called the German map, see the right corner of the copyright information, there is a gray gold map logo, so there is no problem of coordinate conversion, well, natural;

2, Gold launched a global positioning, full English map, full English search (only this one in the country!) ) and other trendy products, various very suitable for the "international fan son" this proposition.

--------------------------------------------------------------------------------------------------------------- ----------------

How the "Gold API" uses Mapkit to develop iOS maps for full English retrieval

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.