CoreLocation MKMapView map, corelocation

Source: Internet
Author: User

CoreLocation MKMapView map, corelocation

Built-in Map Framework: CoreLocation MapKit

CLLocationManager --> positioning manager CLGeocoder --> geographic encoder MKMapView --> map view

Allow user location
[_ LocationManager requestAlwaysAuthorization]; // always allow
[_ LocationManager requestWhenInUseAuthorization]; // allow

The location proxy method is called again only when the user moves 100 meters.
_ LocationManager. distanceFilter = 100.0;

Start locating

[_ LocationManager startUpdatingLocation];

CLLocationManager proxy method: (obtain the information room for processing)

-(Void) locationManager :( CLLocationManager *) manager didUpdateLocations :( NSArray <CLLocation *> *) locations {
}

At which point the proportional coefficient is displayed
MKCoordinateRegion region = MKCoordinateRegionMake (userLocation. coordinate, MKCoordinateSpanMake (0.1, 0.1 ));
Proportional Coefficient Assignment
_ MapView. region = region;


CLGeocoder:

Encoding:Provide a string to locate the location:-(void) geocodeAddressString :( NSString *) addressString completionHandler :( CLGeocodeCompletionHandler) completionHandler;

Anti-encoding:Display the name of the location Based on the location. [_ geocoder handler: placemark. location completionHandler: ^ (NSArray <CLPlacemark *> * _ Nullable placemarks, NSError * _ Nullable error) {}];

Add pin:

AGAnnotion * agAnnotion = [[AGAnnotion alloc] init];
AgAnnotion. coordinate = CLLocationCoordinate2DMake (36.0, 120.0 );
AgAnnotion. title = @ "coco ";
[_ MapView addAnnotation: agAnnotion];
Custom bubble

Inherit NSObject and follow MKAnnotation Protocol

Create three attributes

@ Property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@ Property (nonatomic, copy) NSString * title;
@ Property (nonatomic, copy) NSString * subtitle;

Autonavi:

1. Verify the key
[MAMapServices sharedServices]. apiKey = @ "applied key ";
2. Initialization
MapView = [[MAMapView alloc] initWithFrame: CGRectMake (0, 0, CGRectGetWidth (self. view. frame), CGRectGetHeight (self. view. bounds)];
MapView. delegate = self;
MapView. language = MAMapLanguageEn; // sets the Map Display language.
MapView. mapType = MAMapTypeStandard; // map type
/*
MAMapTypeSatellite: Satellite Map
MAMapTypeStandard: Standard Map
*/

MapView. showTraffic = YES; // display real-time traffic conditions
[Self. view addSubview: mapView];
MapView. showsUserLocation = YES;

Location mode of mapView: userTrackingMode

MAUserTrackingModeNone: displays only on the map without following the user's location.

MAUserTrackingModeFollow: follows the user's position and sets the positioning point to the map center point.

MAUserTrackingModeFollowWithHeading: follows the user's location and Angle

Differences between the system map and AMAP

 

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.