iOS about the German SDK and easy to use

Source: Internet
Author: User
Tags reverse geocoding

 According to the current project needs, maps, positioning into the current app is a very common technology point, now the domestic popular map of the individual summary of the framework, not very comprehensive, but broadly meet the needs of everyone.

1, the system comes with mapkit frame, the framework is relatively high maintenance, but the package is more complicated.

2, the third SDK, we generally choose the German or Baidu.

Let me summarize my experience with the German SDK, and let's take a look at the usage process

1, we first apply for a appkey, apply for Appkey must register the gold developer

    

2, the download of the German SDK, now the SDK has three libraries, according to the integration needs of your app, you can choose to add to their own projects, they are 2D map library, 3D Map Library, as well as a search base;

3, add the SDK into their own project (project), add the time to pay attention to the path problem, after adding the high-end SDK, we also need to add some system comes with libraries, with these to support the operation of the high-powered SDK, they are as

  

4, the configuration of the running environment, add-OBJC in Targets->build settings->other Linker Flaggs.

Or everyone is familiar with cocoapods students want to save the configuration environment and the path of the problem, then we can use pods to configure him, respectively search Amap3dmap,amap2dmap,amapsearch, we look at the general know the use of these three, If you do not know how to manage with pods, I will explain the use of cocoapods in the next blog.

5, next to the people most concerned about the place, that is how to implement the code to display the map, below we will look at the core class inside,

First we want the reality map, Mamapview This is the implementation of the map of the key class, the following see how to show the map in our project, we here first talk about the realization of 2D,

- (void) Viewwillappear: (BOOL) animated{[Super Viewwillappear:yes]; [Mamapservices Sharedservices].apikey=@"a2e716827857a145e86e99ea08cfe15f"; _mapview=[[Mamapview alloc] Initwithframe:[uiscreen mainscreen].bounds]; _mapview.maptype= Mamaptypesatellite;//set map style, satellite_mapview.showtraffic = YES;//turn on real-time traffic conditions_mapview.Delegate=Self ; _mapview.logocenter= Cgpointmake (Cgrectgetwidth (self.view.bounds)- -, the);//Set the center point of the map logo_mapview.showscompass= YES;//set to NO to indicate closing the compass; YES indicates that the compass is displayed_mapview.showsscale= YES;//set to no indicates that the scale bar is not displayed; YES indicates scale bar display_mapview.scaleorigin= Cgpointmake (_mapview.scaleorigin.x, A);//set the bar position_mapview.compassorigin= Cgpointmake (_mapview.compassorigin.x, A);//Setting the compass position_mapview.showsuserlocation= YES;//turn on map positioning[_mapview setusertrackingmode:mausertrackingmodefollow animated:yes];//set User root parcel mode[Self.view Addsubview:_mapview]; Mapointannotation*pointannotation = [[Mapointannotation alloc] init];//Initializing AnnotationsPointannotation.coordinate = Cllocationcoordinate2dmake (39.989631,116.481018);//Set callout geographic coordinatesPointannotation.title =@"Focus Square: International";//Set label headingsPointannotation.subtitle =@"No. 6th, Fu Tong East Street";//Set Callout sub-headings[_mapview addannotation:pointannotation];//Add a callout    }-(Maannotationview *) Mapview: (Mamapview *) Mapview viewforannotation: (ID<MAAnnotation>) annotation{if([Annotation iskindofclass:[mapointannotationclass]]) {            StaticNSString *pointreuseindetifier =@"Pointreuseindetifier"; Mapinannotationview*annotationview = (mapinannotationview*) [Mapview Dequeuereusableannotationviewwithidentifier:pointreuseindetifier]; if(Annotationview = =Nil) {Annotationview=[[Mapinannotationview alloc] initwithannotation:annotation reuseidentifier:pointreuseindetifier]; } annotationview.canshowcallout= YES;//set bubbles to eject, default to NOAnnotationview.animatesdrop= YES;//Set the callout animation display, default to NOannotationview.draggable= YES;//set label can be dragged, default to NO annotationview.pincolor = mapinannotationcolorpurple;            returnAnnotationview; }        returnNil; }- (void) Mapview: (Mamapview *) Mapview didupdateuserlocation: (mauserlocation *) userlocation{//NSLog ("Latitude:%f,longitude:%f", Userlocation.coordinate.latitude,userlocation.coordinate.l ongitude);NSLog (@"Latitude:%f,longitude:%f", Userlocation.coordinate.latitude,userlocation.coordinate.longitude); }

We take a look at viewwillapper inside, these code, here are set some properties of the map, the display map does not look very simple, positioning is a simple technical point, but here we take a look at the focus, half of our application is to enter an address, get a callout, Or get an address based on location,

Insert the map above a callout according to the address, when the callout is initialized we pass in a latitude and longitude,

Location to get the address, positioning can get latitude and longitude, labeled on the map, but the purpose is to output the address,

Then both of these involve a common problem, one is to transfer latitude and longitude to the address, one is based on the address of the latitude and longitude, then these two are a reverse process, we see how to implement this process, in the map development, this is what we call geocoding and anti-coding.

Now we're talking about the German SDK, so the coding process is

- (void) viewdidload {[Super viewdidload]; _search= [[Amapsearchapi alloc] Initwithsearchkey:@"a2e716827857a145e86e99ea08cfe15f"Delegate:self];//Initialize SearchAmapgeocodesearchrequest *georequest = [[Amapgeocodesearchrequest alloc] init];//constructs a Request objectGeorequest.searchtype = Amapsearchtype_geocode;//set to GeoCode styleGeorequest.address =@"Peking University";//AddressGeorequest.city = @[@"Beijing"];//location of the city[_search Amapgeocodesearch:georequest];//Initiate geocoding//additional setup after loading the view, typically from a nib.}#pragmaMark Geocoding succeeded Callback-(void) Ongeocodesearchdone: (amapgeocodesearchrequest *) Request response: (Amapgeocodesearchresponse *) response{if(Response.count = =0) {        return; } nsstring*string= [NSString stringWithFormat:@"%ld", Response.count];  for(Amaptip *tipinchResponse.geocodes) {//Response.geocodes All locations that match the addressNSLog (@"%@", [NSString stringWithFormat:@"%@", tip.description]); }    }

Reverse geocoding is basically consistent with the forward direction. Here's the code.

_search = [[Amapsearchapi alloc] Initwithsearchkey:@"a2e716827857a145e86e99ea08cfe15f"Delegate:self];//Initialize SearchAmapregeocodesearchrequest *georequest = [[Amapregeocodesearchrequest alloc] init];//constructs a Request objectGeorequest.searchtype = Amapsearchtype_regeocode;//set to anti-geocoding styleGeorequest.location = [Amapgeopoint locationwithlatitude:39.000Longitude:116.00];//to set the latitude and longitude of the locationGeorequest.radius = +;//Search RadiusGeorequest.requireextension = YES;//whether to return extended information, default to NO[_search Amapgeocodesearch:georequest];//initiating anti-geocoding#pragmaMark's anti-geocoding success-(void) Onregeocodesearchdone: (amapregeocodesearchrequest *) Request response: (Amapregeocodesearchresponse *) response{if(Response.regeocode! =Nil) {        //working with search resultsNSString *result = [NSString stringWithFormat:@"%@", Response.regeocode]; }}

To make a summary of today's technical points,

1, to achieve the display of the map,

2, insert the dimension, when inserting the latitude and longitude

3, Location services, location services to obtain the latitude and longitude,

4, geocoding and anti-coding

5, positioning, labeling these two points to note, generally we are given an address to want to label on the map above, then we have to geocode it, to locate the latitude and longitude, we need to see the address, then we want to map the latitude and longitude into an address

Today, the simple application of the German SDK is here, if you want to implement a custom layer, search the path, please refer to the official documentation of the German SDK.

  

iOS about the German SDK and easy to use

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.