Common map development code

Source: Internet
Author: User

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;

}

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.