[iOS] the use of high moral map MAMapKit: map display, add pins, navigation, positioning function

Recently in the high moral map based positioning, navigation and add the function of the pin, is hereby recorded… Easy to contact students reference…

First, apply for Key: get user Key

1 access to http://lbs.amap.com/console/key/, the use of High German developer account login

2 in the “KEY management” page, click on the top of the “key” button to turn the input application, select the binding service for the iOS platform, Bundle Identifier (SDK “input acquisition method please refer to: access to Bundle Indentifier), as shown below:

[iOS] the use of high moral map MAMapKit: map display, add pins, navigation, positioning function

Get Bundle ID:iOS bundle access mode

One method:

Through code acquisition, the code is as follows: NSString *bundleIdentifier = [[NSBundle bundleIdentifier];

Method two:

Xcode switch to the General tab to view the Bundle Identifier, as shown below:

[iOS] the use of high moral map MAMapKit: map display, add pins, navigation, positioning function

Two, in front of the map display project configuration work:

In the plist configuration field

Location permission

NSLocationAlwaysUsageDescription: always positioning

NSLocationWhenInUseUsageDescription: location when needed

[iOS] the use of high moral map MAMapKit: map display, add pins, navigation, positioning function

ATS settings: Https protocol

[iOS] the use of high moral map MAMapKit: map display, add pins, navigation, positioning function

Three, go to the official website of the high moral map download need to use SDK, decompression, as shown in figure framework:

[iOS] the use of high moral map MAMapKit: map display, add pins, navigation, positioning function

Map display is the basic function of the map SDK, is the use of map positioning, navigation and other functions of his carrier.

First of all, in the lbs.amap.com/api/ios-sdk/download/ page according to your needs to download the library file and decompression, including:

3D vector map library, extract the MAMapKit.framework file after decompression. 3D vector map effect, you can view the 3D block, full-featured, but also supports offline maps, can help you save traffic. Currently does not support multiple instances of maps.

2D grid map library, extract the MAMapKit.framework file. 2D raster map small size, low energy consumption. Support map multi instance.

Search library, extract the AMapSearchKit.framework file. Search library functions include: POI query, path planning, geocoding and reverse geocoding, bus query and input prompt query

Note: the 3D vector map and the 2D raster map can only be selected for one use, the interface is similar, but the map shows different styles.

1, the new project: a new GDMap_DEMO Application project, as shown in the following figure:,

[iOS] the use of high moral map MAMapKit: map display, add pins, navigation, positioning function

2, configuration Engineering: the introduction of the map library

The directory selected in the project name, the TARGETS-&gt Build Phases-> Link Binary; With Libaries, click the “+” button, click on the “Add Other” button in the pop-up window, select the MAMapKit.framework unpacked file is added to the project.

[iOS] the use of high moral map MAMapKit: map display, add pins, navigation, positioning function

3, the introduction of the AMap.bundle resource file, AMap.bundle resource files stored in the location, the default pin mark view pictures, etc., can be used to develop these resources pictures,

Select the name of the project in the left directory and select Add Files to in the right menu”… Select the AMap.bundle file from MAMapKit.framework-> Resources file, and check the “Copy items needed if” check box, click the “Add” button to add the resource file to the project.

[iOS] the use of high moral map MAMapKit: map display, add pins, navigation, positioning function

4, the introduction of high moral map dependent system library files:

Description:

1 note, 2D said the use of 2D to the grid map file system, 3D said the use of 3D vector map to the system files, Search said the use of library search system needs, 3D (V3.X.X) 3D V3.0.0 vector map later needs a new library.

2.SystemConfiguration.framework, CoreTelephonySecurity.framework, Security.framework is used to statistics app information.

3.iOS9, you need to replace the libz.dylib, libstdc++6.09.dylib, libc++.dylib, libstdc++6.09.tbd, libz.tbd, libc++.tbd.

The operation of the system library is as follows:

The directory selected in the project name, the TARGETS-&gt Build Settings-> Link Binary; With Libaries, click the “+” button, find and select the required Library in the pop-up window (see table below), click “Add” button, the library files added to the project.

Four, map display

1, users in the use of Key configuration: SDK map, Key needs to be done to verify the mechanism of application, add the following code on the map before initialization, configuration before applying Key on the official website: if the map does not show up, please check the key setting is correct.

The appDelegate.m method:

– (BOOL) application: (UIApplication *) application didFinishLaunchingWithOptions: (NSDictionary *) launchOptions {

Override point for customization after application / / launch,

Set key:

[AMapServices sharedServices].apiKey = @ “key application”; / / the latest SDK or use AMapServices

[MAMapServices sharedServices].apiKey = “user @ Key”; / / old SDK

Return YES;

}

2,

1) in the ViewController.m file you want to display the map, the introduction of the MAMapKit.h file, inherit the MAMapViewDelegate protocol, and define the MAMapView object, the sample code is as follows:

#import#[email protected] ViewController (
) / / Map

@property (nonatomic, strong) MAMapView *mapView;

@end

2) in the ViewController.m file corresponding to the method of map initialization, initialization steps:

() construct a MAMapView object; (2). Set proxy; (3). Add MAMapView to Subview in

Initialize the
/ / Map

Self.mapView = [[MAMapView initWithFrame:CGRectMake (0, 64, KScreenWidth, KScreenHeight)] alloc];

_mapView.backgroundColor = [UIColor whiteColor];

Self.mapView.delegate = self;

/ / set positioning accuracy

/ / _mapView.desiredAccuracy = kCLLocationAccuracyBest;

Set / location

/ / _mapView.distanceFilter = 5.0f;

_mapView.zoomEnabled = YES;

/ / normal style

_mapView.mapType = MAMapTypeStandard;

Along with the mobile location / / Map

[_mapView setUserTrackingMode:MAUserTrackingModeFollow animated:YES];

/ / set to NO shut down the YES to show the compass compass;

_mapView.showsCompass= NO;

/ / set the compass position

_mapView.compassOrigin= CGPointMake (_mapView.compassOrigin.x, 22);

/ / set to NO representation does not show scale; YES display scale

_mapView.showsScale= NO;

Set the location / scale

_mapView.scaleOrigin= CGPointMake (_mapView.scaleOrigin.x, 22);

/ / zoom level

[_mapView setZoomLevel:16 animated:YES];

/ / open position

_mapView.showsUserLocation = YES;

[self.view addSubview:self.mapView];

When the location update, will enter the callback position, through the callback function, can get to the location of the latitude and longitude coordinates of the sample code is as follows:

– (void) mapView: (MAMapView *) mapView didUpdateUserLocation: (MAUserLocation *) userLocation updatingLocation: (BOOL) updatingLocation {

//userLocation is the user’s current location information, through the userLocation can get the current latitude and longitude information and detailed geographic information, the method is as follows:

/ / create a point of latitude and longitude:

MAPointAnnotation *point = [[MAPointAnnotation alloc] init];

/ / set points of latitude and longitude

Point.coordinate = _currentUL.location.coordinate;

CLLocation *currentLocation = [[CLLocation alloc]initWithLatitude:_currentUL.location.coordinate.latitude longitude:_currentUL.location.coordinate.longitude];

Initialization / encoder

CLGeocoder *geoCoder = [[CLGeocoder alloc] init];

[geoCoder reverseGeocodeLocation:currentLocation completionHandler:^ (NSArray *placemarks, NSError *error) {

/ / get the current location information of the city, including CLPlacemark name, thoroughfare, subThoroughfare, locality, subLocality and other detailed information

CLPlacemark *mark = [placemarks lastObject];

NSString *cityName = mark.locality;

(NSLog / @ “% @ City”, cityName);

Self.currentCity = cityName;

}];

}

View display:

[iOS] the use of high moral map MAMapKit: map display, add pins, navigation, positioning function

Four, add pins:

Code:

Create / coordinate

CLLocationCoordinate2D coor;

Coor.latitude = @ 39.33232132323″;

Coor.longitude = @ 116.23423423423″;

MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];

PointAnnotation.coordinate = coor;

/ / coordinate location positioned at the center of the map

Self.mapView.centerCoordinate = coor;

Will / / add to the map, which is called a pin

[self.mapView addAnnotation:pointAnnotation];

Add a pin, will enter the MapView proxy method: in the proxy method can be set to display the picture of the pin, and click on the button to pop bubbles view

(MAAnnotationView *) mapView: (MAMapView *) mapView viewForAnnotation: (ID) annotation {

/ / pin mark

If ([annotation isKindOfClass:[MAPointAnnotation class]]) {// to determine whether the bubble positioning themselves, if not their own bubble location, do any settings, display blue points, if the location of bubble is not their own, such as a pin will enter

Static NSString *pointReuseIndentifier @ @ @ pointReuseIndentifier”;

MAAnnotationView*annotationView = (MAAnnotationView*) [mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndentifier];

If (annotationView = = Nil) {

AnnotationView = [[MAAnnotationView initWithAnnotation:annotation alloc] reuseIdentifier:pointReuseIndentifier];

}

AnnotationView.frame = CGRectMake (0, 0, 100, 100);

AnnotationView.canShowCallout= YES; / / set bubbles can pop, the default is NO

//annotationView.animatesDrop = YES; / / set up the mark of animation, the default is NO

AnnotationView.draggable = YES; / / set annotation can drag, the default is NO

/ / annotationView.pinColor = MAPinAnnotationColorPurple;

/ / set the pins show pictures

AnnotationView.image = [UIImage imageNamed:@ “point”];

Click on the left side of the display / pin view

UIImageView *imageV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@ “backImage” “;

AnnotationView.leftCalloutAccessoryView = imageV;

Right click on the display view / pin

UIButton *rightButton = [[UIButton initWithFrame:CGRectMake (0, 0, 80, 50)] (alloc]);

RightButton.backgroundColor = [UIColor grayColor];

[rightButton setTitle:@ “navigation” forState:UIControlStateNormal];

AnnotationView.rightCalloutAccessoryView = rightButton;

/ annotationView.image [UIImage imageNamed:@ = “redPin”];

Return annotationView;

}

Return nil;

}

View renderings:

[iOS] the use of high moral map MAMapKit: map display, add pins, navigation, positioning function

Five, follow-up update navigation function, please continue to focus on…

Recently in the high moral map based positioning, navigation and add the function of the pin, is hereby recorded… Easy to contact students reference…

rightButton.backgroundColor = [UIColor grayColor];

[rightButton setTitle:@”导航” forState:UIControlStateNormal];

annotationView.rightCalloutAccessoryView = rightButton;

//        annotationView.image = [UIImage imageNamed:@”redPin”];

return annotationView;

}

return nil;

}

查看效果图:

[iOS] the use of high moral map MAMapKit: map display, add pins, navigation, positioning function

五、后续更新导航功能,请继续关注。。。