1. Build the UI and import the Mapkit framework
#import <MapKit/MapKit.h>
2. Add a member variable and connect
-*mapview;
3. Basic settings
1- (void) Viewdidload2 {3 [Super Viewdidload];4 //set up a map proxy5Self.mapview.Delegate=Self ;6 //set the tracking mode for the map7Self.mapView.userTrackingMode =Mkusertrackingmodefollow;8 //set the map type to "standard type"9Self.mapView.mapType =Mkmaptypestandard;Ten One}
4. Click the Location button to trigger the method
1 //return to User location2-(ibaction) backuserlocation {3 4 //Default Zone5Mkcoordinatespan Spa = Mkcoordinatespanmake (0.01,0.02);6Mkcoordinateregion region =Mkcoordinateregionmake (self.mapView.userLocation.location.coordinate, spa);7 8 [Self.mapview setCenterCoordinate:self.mapView.userLocation.location.coordinate animated:yes];9 [Self.mapview setregion:region animated:yes];Ten}
Proxy method for 5.MKMapKit
1 #pragmaMark-mkmapviewdelegate2 //This method is called automatically whenever the user's location changes, particularly high frequency3- (void) Mapview: (Mkmapview *) Mapview didupdateuserlocation: (mkuserlocation *) Userlocation4 {5 //set the title of the user's location6Userlocation.title =@"My location-title";7Userlocation.subtitle =@"My Location-sub-title";8 9 //get the latitude and longitude of the userTenCllocationcoordinate2d Center =userlocation.coordinate; OneNSLog (@"My Longitude:%f, Latitude:%f", center.longitude,center.latitude); A - //set the user's location to the map center - [Mapview setcentercoordinate:center animated:yes]; the - //set span (latitude and longitude) -Mkcoordinatespan Spa = Mkcoordinatespanmake (0.01,0.02); - //Set Area (center point and span) +Mkcoordinateregion region =Mkcoordinateregionmake (center, Spa); - //set the display area of a map + [Mapview setregion:region animated:yes]; A at } - - /** - * This method is automatically called as long as the display area of the map changes, so you can use this method to get the current region information (center point and Span) of the map . - */ -- (void) Mapview: (Mkmapview *) Mapview regiondidchangeanimated: (BOOL) Animated in { - toMkcoordinatespan span =MapView.region.span; +NSLog (@"latitude span%f, longitude span%f", Span.latitudedelta, Span.longitudedelta); -}
Basic use of IOS Mapkit