Location and map: Map usage

Source: Internet
Author: User
1. Basic concepts of mapkit
  • Use the core location framework to obtain the location information of the current device, and use the mapkit framework to display this information.
  • When using the map service, you need to add the mapkit. Framework framework
  • Most functions of mapkit are completed by mkmapview, which is mainly responsible for map display.
2. Sample Code

Code in. h

#import <MapKit/MapKit.h>@interface MainViewController : UIViewController<MKMapViewDelegate,CLLocationManagerDelegate>@property (strong, nonatomic) IBOutlet MKMapView *mapView;</span>

Code in. m


// Set whether to display the user's current position self. mapview. showsuserlocation = yes; // sets the proxy self. mapview. delegate = self; // set the map display type // mkmaptypestandard standard type // mkmaptypesatellite satellite // mkmaptypehybrid hybrid self. mapview. maptype = mkmaptypestandard; // coordinate cllocationcoordinate2d coord = {40.029254, 116.337254}; // display range precision mkcoordinatespan span = {0.1, 0.1 }; // display region mkcoordinateregion region = {coord, span}; // map location during map initialization [self. mapview setregion: region];



3. Common map delegation Methods

Return to the annotation view (PIN view)

-(Mkannotationview *) mapview :( mkmapview *) mapview viewforannotation :( id <mkannotation>) Annotation

Called when updating the current location

-(Void) mapview :( mkmapview *) mapview didupdateuserlocation :( mkuserlocation *) userlocation;

Select annotation View

-(Void) mapview :( mkmapview *) mapview didselectannotationview :( mkannotationview *) view

Called when the display area of the map changes

-(Void) mapview :( mkmapview *) mapview regiondidchangeanimated :( bool) animated


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.