//
Viewcontroller.m
Demo_1 Mkmapview
//
Created by Tareba on 15/12/16.
copyright©2015 year Tanada. All rights reserved.
//
#import "ViewController.h"
#import <MapKit/MapKit.h>
#import "TRAnnotation.h"
@interface Viewcontroller () <mkmapviewdelegate>
@property (weak, nonatomic) iboutlet mkmapview *mapview;
/**
* same point : ask the user for permission
*/
@property (nonatomic,strong)Cllocationmanager *manager;
-(ibaction) addannotation: (UIButton *) sender;
@end
@implementation Viewcontroller
-(void) viewdidload {
[Super viewdidload];
// Initialize manger
self. Manager=[[cllocationmanager alloc]init];
// ask for permission from the user
[self. Manager requestwheninuseauthorization];
//delegate
self. Mapview. Delegate=self;
// set map not allowed to rotate
self. Mapview. rotateenabled=NO;
// Set the display type of the map ( satellite / Shore quasi map / hybrid )
//self.mapview.maptype=mkmaptypehybrid;
// start positioning
self. Mapview. Usertrackingmode=mkusertrackingmodefollow;
}
#pragma mark-mapviewdelegate
has been positioned to the user's location and finished displaying
-(void) Mapview: (mkmapview *) Mapview didupdateuserlocation: (mkuserlocation *) userlocation{
NSLog(@ " dimension %f, precision %f", userlocation. Location. Coordinate. Latitude, userlocation. Location. Coordinate. Longitude);
Userlocation. title=@ " User location ";
Userlocation. subtitle=@ " description information ";
}
-(void) Mapview: (mkmapview *) Mapview regionwillchangeanimated: (BOOL) animated{
NSLog(@ "The map is going to move ");
}
Make sure the map has moved
-(void) Mapview: (mkmapview *) Mapview regiondidchangeanimated: (BOOL) animated{
NSLog(@ "The map has moved ");
}
-(ibaction) addannotation: (UIButton *) Sender {
// Create model class
// Compliance Agreement
//.h Declaration of three attributes 1 must , two Optional
// Add to map view ( mkannotation protocol must be followed )
cllocationdegrees latitude = 35.123+arc4random_uniform(ten); 0~10
cllocationdegrees longitude = 116.125+arc4random_uniform();
trannotation *annotation=[trannotation new];
Annotation. coordinate=cllocationcoordinate2dmake(latitude, longitude);
// Set the display area of the map view ( pins are displayed in the center of the View )
// span
mkcoordinatespan span=mkcoordinatespanmake(0.5, 0.52);
// Center position and span
mkcoordinateregion region=mkcoordinateregionmake(annotation. Coordinate, span);
[self. Mapview setregion: Region animated:YES];
[self. Mapview addannotation: annotation];
}
@end
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface trannotation: nsobject<mkannotation>
@property (nonatomic, assign) cllocationcoordinate2d coordinate;
@property (nonatomic, copy) nsstring *title;
@property (nonatomic, copy) nsstring *subtitle;
@end
Simple operation for native map positioning Mapkit use