Basic use of IOS Mapkit

Source: Internet
Author: User

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

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.