1. // update the visible area of the map so that all bus stops are in the visible area of the map.
-(Void) updatemapviewvisibleregion {
Mkmaprect zoomrect =
Mkmaprectnull;
For (ID <mkannotation> Annotation
In self. mapview. Annotations ){
Mkmappoint annotationpoint =
Mkmappointforcoordinate (annotation. Coordinate );
Mkmaprect pointrect =
Mkmaprectmake (annotationpoint. X, annotationpoint. y,
0, 0 );
If (mkmaprectisnull (zoomrect )){
Zoomrect = pointrect;
}
Else {
Zoomrect =
Mkmaprectunion (zoomrect, pointrect );
}
}
Zoomrect = [self. mapview
Maprectthatfits: zoomrect];
[Self. mapview
Setvisiblemaprect: zoomrect animated: Yes];
}
-(Mkannotationview *) mapview :( mkmapview *) mapview viewforannotation :( ID
<Mkannotation>) annotation {
// Determine whether it is its own location
If ([annotation iskindofclass: [mkuserlocation
Class]) {
Return nil;
}
// Verify Parameters
If (! [Annotation iskindofclass: [zpmkannotation
Class]) {
Return nil;
}
Static
Nsstring * stridentifier =
@ "Mapviewrouteannotationviewidentifier ";
Mkpinannotationview * pinview = (mkpinannotationview *) [mapview
Dequeuereusableannotationviewwithidentifier: stridentifier];
If (nil = pinview ){
Pinview = [[[mkpinannotationview
Alloc] initwithannotation: Annotation
Reuseidentifier: stridentifier]
Autorelease];
Pinview. Tag = (zpmkannotation *) annotation). stationid;
Pinview. pincolor =
Mkpinannotationcolorgreen;
Pinview. canshowcallout =
Yes;
Pinview. rightcalloutaccessoryview = [uibutton
Buttonwithtype: uibuttontypedetaildisclosure];
Pinview. draggable =
Yes;
} Else {
Pinview. annotation = annotation;
}
Return pinview;
}
2. draw lines on a map
// Update the visible area of the map so that all bus stops are in the visible area of the map.
-(Void) updatemapviewvisibleregion {
Mkmaprect zoomrect =
Mkmaprectnull;
For (ID <mkannotation> Annotation
In self. mapview. Annotations ){
Mkmappoint annotationpoint =
Mkmappointforcoordinate (annotation. Coordinate );
Mkmaprect pointrect =
Mkmaprectmake (annotationpoint. X, annotationpoint. y,
0, 0 );
If (mkmaprectisnull (zoomrect )){
Zoomrect = pointrect;
}
Else {
Zoomrect =
Mkmaprectunion (zoomrect, pointrect );
}
}
Zoomrect = [self. mapview
Maprectthatfits: zoomrect];
[Self. mapview
Setvisiblemaprect: zoomrect animated: Yes];
}
-(Mkoverlayview *) mapview :( mkmapview *) mapview viewforoverlay :( id <mkoverlay>) Overlay
{
If (overlay = self. routeline ){
Self. routelineview = [[mkpolylineview
Alloc] initwithpolyline: Self. routeline]
Autorelease];
Self. routelineview. fillcolor = [uicolor
Bluecolor];
Self. routelineview. strokecolor = [uicolor
Bluecolor];
Self. routelineview. linewidth =
5;
Return self. routelineview;
}
Return
Nil;
}