<title></title>
MARK: in the Google map created in the previous example, with the position (pois) added, the position selection will generate the corresponding event.
☉Restrictions: You must update the iPhone operating systemOS 3.0Version.Sdks 3.0Internal CreationMapkit framework.
☉Effect plane:
☉Step by step:
Each location on the geographic chart is a mkannotationview, that is, the UI. Each mkannotationview requires a corresponding resource mkannotation. This is protocal, that is, the information required for storing each base point. Therefore, we need to first create a class that uses mkannotation.
According to the iPhone issuer's documentation. This protocal requires three features and an initialization method. The three features are coordinate, title, subtitle, and initwithcoords.
The following is the program mongopoi. H of the mkannotation type.
# Import
# Import
# Import
@ Interface poi: nsobject
{
Cllocationcoordinate2d coordinate;
Nsstring * subtitle;
Nsstring * title;
}
@ Property (nonatomic, readonly) cllocationcoordinate2d coordinate;
@ Property (nonatomic, retain) nsstring * subtitle;
@ Property (nonatomic, retain) nsstring * title;
-(ID) initwithcoords :( cllocationcoordinate2d) coords;
@ End
The following is the program named POI. m for mkannotation.
# Import "Poi. H"
@ Implementation poi
@ Synthesize coordinate, subtitle, title;
-(ID) initwithcoords :( cllocationcoordinate2d) coords {
Self = [Super init];
If (self! = Nil ){
Coordinate = coords;
}
Return self;
}
-(Void) dealloc
{
[Title release];
[Subtitle release];
[Super dealloc];
}
@ End
After declaring the class that complies with mkannotation protocal, we need to establish a base point on Google map. Show Google map programs on the iPhone to take the test againUse mkmapview for Google Map.
Next,
STEP (1): I announced a function called createmappoint to build a base point. Here we use the other poi we announced earlier (this is a similar to mkannotation Protocal), we create a poi, then, we will introduce the economic, standard, and sub-standard information required for the base point. Next call
[Mapview addannotation: poi];
Add the created poi to the annotation set of the region (mkmapview.OnlyBase Point InformationAt this time, no real base points have been set up..
The createmappoint program example is as follows:
# Import "Poi. H"
-(Void *) createmappoint :( mkmapview *) mapview coordinatex :( double) coorx coordinatey :( double) coory
Title :( nsstring *) Title subtitle :( nsstring *) Subtitle {
If (mapview! = Nil ){
// Set poi lat and LNG
Cllocationcoordinate2d P1;
Poi * poi;
If (coorx & coory ){
P1.latitude = coorx;
P1.longpolling = coory;
Poi = [[poi alloc] initwithcoords: P1];
If (title! = NULL)
Poi. Title = title;
If (Subtitle! = NULL)
Poi. Subtitle = subtitle;
[Mapview addannotation: poi];
[Poi release];
}
}
Return NULL;
}
STEP (2): You can see the description file of mkmapview.ViewforannotationThis method is the place where mkmapview creates a base point.. When mkmapview is used in the render region, the base point is set based on the information of the annotation set.
-(Mkannotationview *) mapview :( mkmapview *) mapview viewforannotation :( id <mkannotation>) annotation {
// Method 1: Using default pin as a placemarker to display on Map
Mkpinannotationview * newannotation = [[mkpinannotationview alloc] initwithannotation: annotation reuseidentifier: @ "annotation1"];
Newannotation. pincolor = mkpinannotationcolorgreen;
Newannotation. animatesdrop = yes;
// Canshowcallout: to display the callout view by touch the pin
Newannotation. canshowcallout = yes;
Uibutton * button = [uibutton buttonwithtype: uibuttontypedetaildisclosure];
[Button addtarget: Self action: @ selector (checkbuttontapped: Event :) forcontrolevents: uicontroleventtouchupinside];
Newannotation. rightcalloutaccessoryview = button;
Return newannotation;
// Method 2: using the image as a placemarker to display on Map
/*
Mkannotationview * newannotation = [[mkannotationview alloc] initwithannotation: annotation reuseidentifier: @ "annotation1"];
Newannotation. Image = [uiimage imagenamed: @ "icon.png"];
Newannotation. canshowcallout = yes;
Return newannotation;
*/
}
The vieforannotation method in the annotation set will be processed twice. Therefore, every time viewforannotation is executed, we need to create a mkannotationview object and return the object. When mkmapview receives the mkannotationview, it will be displayed on the region. This is the location we want to display on the region. Mkpinannotationview is used in the program above. This object is hosted by mkannotationview and is used to display a large header on the geographic chart. You can use
Annotationview. pincolor = mkpinannotationcolorgreen;
Set the colors of the big head, But there are only three colors (it seems a little sparse xd), which are colors: red, purple, and yellow ).
Newannotation. canshowcallout = yes;
Determines whether the bubble window appears when you select a large node.. 10th rows to 12th rows create a detaildisclousue type press, set a uicontroleventtouchupinside event for this press, and put it in the accessoryview of the bubble window. Finally, the created slot is returned to mapview. The second method to be resolved is to directly use mkannotationview to create a base point and set her image modularity,Therefore, the location is not necessarily a big head, There can be more changes and flowers.
-(Void) checkbuttontapped :( ID) sender event :( ID) event {
Uialertview * TMP = [[uialertview alloc] initwithtitle: @ "interest! "Message: @" callout failed "delegate: Nil cancelbuttontitle: @" OK "otherbuttontitles: Nil];
[TMP show];
[TMP release];
}
The above is the event handling Regular Expression of the row in the uicontroleventtouchupinside event. When detaildisclousue is selected, an alert will pop out, indicating that the event is handled correctly.
In this example, we can see the relationship between mkannotation and mkannotationview.