Ios:uimapview simple use of the map view control

Source: Internet
Author: User

You can set the map type by setting the Mapviewtype of Mkmapview

Mkmaptypestandard General Mapmkmaptypesatellite Satellite CloudMkmaptypehybrid General Map overlay on satellite imagery

@property (nonatomic) Mkmaptype Maptype; Map type

@property (nonatomic) Mkcoordinateregion region; Location Area

@property (nonatomic) cllocationcoordinate2d centercoordinate;//position latitude and longitude

Location Area range (0~1)

typedef struct {

Cllocationdegrees Latitudedelta;

Cllocationdegrees Longitudedelta;

} Mkcoordinatespan;

Latitude and longitude of position

typedef struct {

Cllocationdegrees latitude;

Cllocationdegrees longitude;

} cllocationcoordinate2d;

Location Area

typedef struct {

Cllocationcoordinate2d Center;

Mkcoordinatespan span;

} mkcoordinateregion;

Mapview will pass some events to its agent (following the Mkmapviewdelegate protocol), and the proxy method is as follows:Mapviewwillstartloadingmap: Called when the map interface is going to be loadedMapview:viewforannotation: Called when there are some animation effects on the map \ LoadMapviewwillstartlocatinguser: Called when a position is ready to be positionedmapview:regiondidchangeanimated: Called when the displayed area is changedMapview:didupdateuserlocation: Called when the user location has changedThe concrete examples are as follows:1. Import Corelocation/mapkit Frame2. Drag into a Uimapview control into the controller3. Import the necessary library files in the viewcontroller.m file4. Associate the Mapview with the Iboutlet attribute while allowing the Viewcontroller class to implement the map protocol5. Code implementation Function//Show Map
- (void) viewdidload {[Super viewdidload]; //set the properties of a mapSelf.mapView.mapType =Mkmaptypehybrid; //set latitude and longitude coordinates for a regioncllocationcoordinate2d coordinate = Cllocationcoordinate2dmake ( +, the);//(longitude, latitude)//set the latitude and longitude range (the smaller the more accurate)Mkcoordinatespan span = Mkcoordinatespanmake (0.1,0.1); //set the area of the map displaySelf.mapView.region =mkcoordinateregionmake (coordinate, span); //set up a proxy for a mapSelf.mapview.Delegate=Self ;}

Implementing a Map protocol

Methods of #pragma mark-mapview

#pragmaMark-The map starts loading-(void) Mapviewwillstartloadingmap: (Mkmapview *) mapview{NSLog (@"Start loading Map");}#pragmaMark-The map is loaded-(void) Mapviewdidfinishloadingmap: (Mkmapview *) mapview{NSLog (@"Map Loading Complete");}#pragmaMark-The map area is going to change-(void) Mapview: (Mkmapview *) Mapview regionwillchangeanimated: (BOOL) animated{mkcoordinateregion Region=mapview.region; NSLog (@"Longitude:%f, Latitude:%f", region.center.latitude,region.center.longitude);}#pragmaMark-the map area has changed-(void) Mapview: (Mkmapview *) Mapview regiondidchangeanimated: (BOOL) animated{mkcoordinateregion Region=mapview.region; NSLog (@"Longitude:%f, Latitude:%f", region.center.latitude,region.center.longitude);}

Demo Result:

The load invokes the proxy method, and the output is:

£ º19.241--mapkit-mapview[  7278:360386] Start loading map -ten:50 :19.261-mapkit-mapview[7278:360386] Map loading complete

The map shows:

Ios:uimapview simple use of the map view control

Related Article

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.