iOS development--Introduction to the use of the German map SDK

Source: Internet
Author: User

The open platform will be the most professional positioning, map, search, navigation and other capabilities to the API, SDK and other forms of free access to the vast number of developers. In this section, let's take a quick look at how to use its location and Map SDK.

I. Relevant framework and environment configuration
    • Map SDK

For how to download the SDK, its official documentation provides a very detailed description of the use of cocoapods. If you do not have Cocoapods installed, you can also download it directly on its website.

The next step is to introduce the SDK into the project and complete the relevant environment configuration. It is detailed in its official documentation and is not repeated here.

Map SDK Documentation

    • Locating the SDK

The German IOS Locator SDK provides positioning capabilities that do not depend on map positioning, and developers can easily add positioning to applications without a map display. The continuous positioning function provided in the Location SDK is separated from the map function. Let's also download the SDK first.

Since the location is different from the Map SDK, be sure to set the user key to two times.

It is also important to note that in official documents the environment configuration for Targets-build Settings-architectures is different in the location and Map SDK, but you can just set one of them.

Locating the SDK documentation

Second, the sample code

    • Introduce the relevant framework and complete the environment configuration

In its official documentation, there is a detailed description of what framework is needed, which is added according to the documentation.

Finally according to the documentation we need to set up the Info.plist file.

    • Complete Apikey settings in the APPDELEGATE.M file
    1. #import <mamapkit/mamapkit.h>//Map SDK header file
    2. #import <amaplocationkit/amaplocationkit.h>//locating the SDK header file
  1. - (BOOL)application:(uiapplication *)Application Didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {
  2. [mamapservices sharedservices]. ApiKey = @"990c9f469d381bd72a6915b3d0c829a5"; Map SDK
  3. [amaplocationservices sharedservices]. ApiKey [email protected]"990C9F469D381BD72A6915B3D0C829A5"; Locating the SDK
  4. return YES;
  5. }
    • Introduce the desired attribute in the VIEWCONTROLLER.M file and complete lazy loading
    1. #import <MAMapKit/MAMapKit.h>
    2. #import <AMapLocationKit/AMapLocationKit.h>
  1. @interface viewcontroller () <mamapviewdelegate,amaplocationmanagerdelegate >
  2. @property (nonatomic, strong) mamapview *mapview; Map view
  3. @property (nonatomic, strong) amaplocationmanager * Locationmanager; Location Manager
  4. @end
  1. - (mamapview *)mapview{
  2. if (! _mapview) {
  3. _mapview = [[mamapview Alloc] Initwithframe: Cgrectmake (0, 0, cgrectgetwidth (selfview. cgrectgetheight ( self. View. Bounds
  4. _mapview. Delegate = self ;
  5. _mapview. Maptype = mamaptypestandard; Set the map type
  6. _mapview. Showtraffic= YES; Whether to show traffic map
  7. [self. Locationmanager startupdatinglocation]; //start positioning
  8. [_mapview setusertrackingmode: mausertrackingmodefollow animated:YES]; The layer that changes the map is displayed after positioning.
  9. [self. View Addsubview:_mapview];
  10. }
  11. return _mapview;
  12. }
  13. - (amaplocationmanager *)locationmanager{
  14. if (! _locationmanager) {
  15. _locationmanager = [[amaplocationmanager alloc] init];
  16. _locationmanager. Delegate = self ;
  17. }
  18. return _locationmanager;
  19. }
  20. - (void)viewdidload {
  21. [Super Viewdidload];
  22. [self locationmanager];
  23. [self mapview];
  24. }
    • Complete positioning and "pin" functions
  1. The Amaplocationmanager proxy method location is updated after the callback.
  2. - (void)amaplocationmanager:(amaplocationmanager *)Manager Didupdatelocation:(cllocation *) Location
  3. {
  4. NSLog(@"location:{lat:%f; lon:%f; ACCURACY:%F} ", location. Coordinate. Latitude, location. Coordinate. Longitude, location. Horizontalaccuracy);
  5. }
  6. -(void) viewdidappear:(BOOL)animated
  7. {
  8. [Super Viewdidappear:animated];
  9. mapointannotation *pointannotation = [[mapointannotation alloc] init];
  10. Pointannotation. Coordinate = cllocationcoordinate2dmake(31.982527, 118.735046);
  11. Pointannotation. Title = @"Acer Chong Technology";
  12. Pointannotation. Subtitle = @"national advertising industry Park XXX";
  13. [self. Mapview addannotation:pointannotation];
  14. }
  15. Mamapview Proxy method for setting a PIN
  16. - (maannotationview *)mapview:(mamapview *)Mapview Viewforannotation:(ID )annotation
  17. {
  18. if ([annotation iskindofclass: [mapointannotation class]])
  19. {
  20. static nsstring *pointreuseindentifier = @"Pointreuseindentifier ";
  21. Mapinannotationview*annotationview = (mapinannotationview*) [Mapview Dequeuereusableannotationviewwithidentifier:pointreuseindentifier];
  22. if (annotationview = = nil)
  23. {
  24. Annotationview = [[mapinannotationview alloc] initwithannotation:annotation Reuseidentifier:pointreuseindentifier];
  25. }
  26. Annotationview. Canshowcallout= YES; //Set bubbles to eject, default to No
  27. Annotationview. Animatesdrop = YES; //Set callout animation display, default to No
  28. Annotationview. Draggable = YES; //Set callout to drag, default to No
  29. Annotationview. Pincolor = mapinannotationcolorpurple;
  30. return Annotationview;
  31. }
  32. return nil;
  33. }

iOS development--Introduction to the use of the German map SDK

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.