1, add the Map interface Mkmapview (full screen) in VC
2, select the project boundary of the interface corresponding to the second line, the Build phases option to choose the third + number, pop-up search box input mapk, select the search results confirm add, the map can be displayed.(3. The right-hand side of the map in SB has three modes, (two-dimensional line, satellite-free, satellite cable)) 4, the Association code in the VC Association MYMV. However, it is not recognized by the system at this time to addimport<mapkit/mapkit.h> Protocol, at this time to be recognized 5, at this time to obtain from the network latitude and longitude, such as Tiananmen Square latitude and longitude, at this time to use the method-create a latitude and longitude structure:
Latitude: 39.90960456049752
Longitude: 116.3972282409668
This is the structure of latitude and longitude * *
Cllocationcoordinate2d coord = Cllocationcoordinate2dmake (39.90960456049752, 116.3972282409668);
This represents the zoom level * * *
Mkcoordinatespan span = Mkcoordinatespanmake (. 001,. 001);
And at this point to create a structure to load the latitude and longitude and zoom levels together, so that the map display to the location of the development:
[Self.mymv setregion:mkcoordinateregionmake (coord, span)];
6. Add a pin to the map:
You need to create a custom class that inherits NSObject named Myannotation. At this point, you want this class to import<mapkit/mapkit.h> in. h, and implement a protocol:
@interface myannotation:nsobject<mkannotation> ———— But this protocol has some limitations, to add attributes to it, to enter the protocol, which has a must and two optional attributes, to copy all three of them. In H:
@property (nonatomic, readonly) cllocationcoordinate2d coordinate;
@property (nonatomic, readonly, copy) NSString *title;
@property (nonatomic, readonly, copy) NSString *subtitle;
ReadOnly is read-only meaning, cannot be edited, modified, so removed, so:
@property (nonatomic) cllocationcoordinate2d coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
7, at this time in the VC import myannotation,
To add a pin in VDL:
Myannotation *ann = [[myannotation alloc]init];--Add a pin to an object
Ann.coordinate = coord;--This is the latitude and longitude of a pin.
Ann. Title = @ "Tiananmen Square ";--This is the header of the pin content
Ann. Subtitle = @ "I love Beijing Tian ' an gate!" " ; ———— Note Content
[SELF.MYMV Addannotation:ann];
————————————————————————————————————————————————————
8. Add a custom pin:
Create a new class to inherit from Mkannotationview ( if you want to drag into Mkmapview in SB)
Name is Mkannotationview
and connect the delegate line in SB.
9. Add an agreement to the VC
@interface Viewcontroller () <MKMapViewDelegate>
Enter this agreement,
Copy it out.
-(Mkannotationview *) Mapview: (Mkmapview *) Mapview viewforannotation: (id <MKAnnotation>) annotation{
—————— Reuse Effect
Importing import "Mkannotationview"
Write in method
Myannotationview *av = (Myannotationview *) is a content of this type in this () [Mapview Dequeuereusableannotationviewwithidentifier: @ "Ann"];
if (!AV) {
AV = [[Myannotationview alloc]initwithannotation:annotation reuseidentifier:@ "Ann"];
}
return AV;
}
Initialize in myannotationview.m
-(Instancetype) Initwithannotation: (id<mkannotation>) annotation reuseidentifier: (NSString *) reuseIdentifier
{
self = [super initwithannotation:annotation reuseidentifier:reuseidentifier];
if (self) {
Modify the style of a pin
Self.image = [UIImage imagenamed:@ "Index_map.png"];
return self;
}
The display is now complete.
————————————————————————
Note: You can add any object in this initialization method,
11. You can also add other pins to other coordinates at this time.
First get latitude and longitude,
Then add the ANN2 in the VC
Myannotation *ann2 = [[Myannotation alloc]init];
Ann2.coordinate = Cllocationcoordinate2dmake (39.8068719483, 116.4608274052);
[SELF.MYMV ADDANNOTATION:ANN2];
12. When the pin is clicked the event appears:
Enter the protocol and find the method: When the display area changes .
-(void) Mapview: (Mkmapview *) Mapview regiondidchangeanimated: (BOOL) animated{
Myannotation *ann2 = [[Myannotation alloc]init];
Ann2.coordinate = mapview.centercoordinate; ( screen display center)
[SELF.MYMV ADDANNOTATION:ANN2];
}
At this point, add a pin to the center each time you move
13, re-enter the agreement to find the method: Click on the selected
-(void) Mapview: (Mkmapview *) Mapview Didselectannotationview: (Mkannotationview *) view{
NSLog (@ "Click on a Pin");
}
1, add the Map interface Mkmapview (full screen) in VC
2, select the project boundary of the interface corresponding to the second line, the Build phases option to choose the third + number, pop-up search box input mapk, select the search results confirm add, the map can be displayed.(3. The right-hand side of the map in SB has three modes, (two-dimensional line, satellite-free, satellite cable)) 4, the Association code in the VC Association MYMV. However, it is not recognized by the system at this time to addimport<mapkit/mapkit.h> Protocol, at this time to be recognized 5, at this time to obtain from the network latitude and longitude, such as Tiananmen Square latitude and longitude, at this time to use the method-create a latitude and longitude structure:
Latitude: 39.90960456049752
Longitude: 116.3972282409668
This is the structure of latitude and longitude * *
Cllocationcoordinate2d coord = Cllocationcoordinate2dmake (39.90960456049752, 116.3972282409668);
This represents the zoom level * * *
Mkcoordinatespan span = Mkcoordinatespanmake (. 001,. 001);
And at this point to create a structure to load the latitude and longitude and zoom levels together, so that the map display to the location of the development:
[Self.mymv setregion:mkcoordinateregionmake (coord, span)];
6. Add a pin to the map:
You need to create a custom class that inherits NSObject named Myannotation. At this point, you want this class to import<mapkit/mapkit.h> in. h, and implement a protocol:
@interface myannotation:nsobject<mkannotation> ———— But this protocol has some limitations, to add attributes to it, to enter the protocol, which has a must and two optional attributes, to copy all three of them. In H:
@property (nonatomic, readonly) cllocationcoordinate2d coordinate;
@property (nonatomic, readonly, copy) NSString *title;
@property (nonatomic, readonly, copy) NSString *subtitle;
ReadOnly is read-only meaning, cannot be edited, modified, so removed, so:
@property (nonatomic) cllocationcoordinate2d coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
7, at this time in the VC import myannotation,
To add a pin in VDL:
Myannotation *ann = [[myannotation alloc]init];--Add a pin to an object
Ann.coordinate = coord;--This is the latitude and longitude of a pin.
Ann. Title = @ "Tiananmen Square ";--This is the header of the pin content
Ann. Subtitle = @ "I love Beijing Tian ' an gate!" " ; ———— Note Content
[SELF.MYMV Addannotation:ann];
————————————————————————————————————————————————————
8. Add a custom pin:
Create a new class to inherit from Mkannotationview ( if you want to drag into Mkmapview in SB)
Name is Mkannotationview
and connect the delegate line in SB.
9. Add an agreement to the VC
@interface Viewcontroller () <MKMapViewDelegate>
Enter this agreement,
Copy it out.
-(Mkannotationview *) Mapview: (Mkmapview *) Mapview viewforannotation: (id <MKAnnotation>) annotation{
—————— Reuse Effect
Importing import "Mkannotationview"
Write in method
Myannotationview *av = (Myannotationview *) is a content of this type in this () [Mapview Dequeuereusableannotationviewwithidentifier: @ "Ann"];
if (!AV) {
AV = [[Myannotationview alloc]initwithannotation:annotation reuseidentifier:@ "Ann"];
}
return AV;
}
Initialize in myannotationview.m
-(Instancetype) Initwithannotation: (id<mkannotation>) annotation reuseidentifier: (NSString *) reuseIdentifier
{
self = [super initwithannotation:annotation reuseidentifier:reuseidentifier];
if (self) {
Modify the style of a pin
Self.image = [UIImage imagenamed:@ "Index_map.png"];
return self;
}
The display is now complete.
————————————————————————
Note: You can add any object in this initialization method,
11. You can also add other pins to other coordinates at this time.
First get latitude and longitude,
Then add the ANN2 in the VC
Myannotation *ann2 = [[Myannotation alloc]init];
Ann2.coordinate = Cllocationcoordinate2dmake (39.8068719483, 116.4608274052);
[SELF.MYMV ADDANNOTATION:ANN2];
12. When the pin is clicked the event appears:
Enter the protocol and find the method: When the display area changes .
-(void) Mapview: (Mkmapview *) Mapview regiondidchangeanimated: (BOOL) animated{
Myannotation *ann2 = [[Myannotation alloc]init];
Ann2.coordinate = mapview.centercoordinate; ( screen display center)
[SELF.MYMV ADDANNOTATION:ANN2];
}
At this point, add a pin to the center each time you move
13, re-enter the agreement to find the method: Click on the selected
-(void) Mapview: (Mkmapview *) Mapview Didselectannotationview: (Mkannotationview *) view{
NSLog (@ "Click on a Pin");
}
IOS Maps--Learning notes in Lan Yi education