Import Baidu Map
Initialize Baidu Map
Mapview = [[Bmkmapview alloc]initwithframe: (cgrect) {0,0,viewwith,viewhight}];
[Self.view Addsubview:mapview];
Mapview.delegate = self;
Add lines and coordinate objects
Allarray inside is the latitude
if (Allarray.count > 2) {
Cllocationcoordinate2d coords[2];
for (Nsinteger i = 0; i < (allarray.count-1); i++) {
NSString *str = Allarray[i];
Nsarray *temp = [str componentsseparatedbystring:@ ","];
NSString *lon = temp[0];
NSString *lat = temp[1];
bmkpointannotation* annotation1 = [[Bmkpointannotation alloc]init];
Cllocationcoordinate2d Coor1;
Coor1.latitude = [lat doublevalue];
Coor1.longitude = [lon Doublevalue];
Annotation1.coordinate = Coor1;
Annotation1.title =[nsstring stringwithformat:@ "%@", Placename[i]];
[Mapview Addannotation:annotation1];
NSLog (@ "%@--%@", Lon,lat);
cllocationcoordinate2d coordinate = Cllocationcoordinate2dmake ([lon Doublevalue], [lat doublevalue]);
Coords[0].latitude = [lat doublevalue];
Coords[0].longitude = [lon Doublevalue];
_number = i;
NSString *STR2 = allarray[i + 1];
Nsarray *TEMP2 = [str2 componentsseparatedbystring:@ ","];
NSString *lon2 = temp2[0];
NSString *lat2 = temp2[1];
NSLog (@ "%@--%@", LON2,LAT2);
Cllocationcoordinate2d coordinate2 = Cllocationcoordinate2dmake ([lat2 doublevalue], [Lon2 doublevalue]);
Coords[1].latitude = [Lat2 doublevalue];
Coords[1].longitude = [Lon2 doublevalue];
Bmkpolyline *mypolyline = [Bmkpolyline polylinewithcoordinates:coords count:2];
[Mapview Addoverlay:mypolyline];
}
}
Custom Coordinate objects
This agent is a line.
-(Bmkoverlayview *) Mapview: (Bmkmapview *) Mapview Viewforoverlay: (id <BMKOverlay>) overlay{
if ([Overlay Iskindofclass:[bmkpolyline class]]) {
bmkpolylineview* Polylineview = [[Bmkpolylineview alloc] initwithoverlay:overlay];
Polylineview.strokecolor = [[Uicolor purplecolor] colorwithalphacomponent:1];
Polylineview.linewidth = 5.0;
return polylineview;
}
return nil;
}
This agent is a coordinate object.
-(Bmkannotationview *) Mapview: (Bmkmapview *) Mapview viewforannotation: (id <BMKAnnotation>) annotation
{
if ([Annotation iskindofclass:[bmkpointannotation class]]) {
UIView *viewforimage=[[uiview alloc]initwithframe:cgrectmake (0, 0, 132, 64)];
Bmkpinannotationview *newannotationview = [[Bmkpinannotationview alloc] Initwithannotation:annotation reuseidentifier:@ "Myannotation"];
Newannotationview.pincolor = Bmkpinannotationcolorpurple;
Newannotationview.animatesdrop = yes;//Sets the callout point animated display
//
UIView *viewforimage=[[uiview alloc]initwithframe:cgrectmake (0, 0, 45, 45)];
Uiimageview *imageview=[[uiimageview alloc]initwithframe:cgrectmake (0, 0, 45, 45)];
[ImageView setimage:[uiimage imagenamed:[nsstring stringwithformat:@ "%d", _number-1]];
[Viewforimage Addsubview:imageview];
UILabel *label=[[uilabel Alloc]initwithframe:cgrectmake (32, 0, 100, 64)];
[Email protected] "Chen Dishu";
Label.backgroundcolor=[uicolor Clearcolor];
[Viewforimage Addsubview:label];
Newannotationview.image=[self Getimagefromview:viewforimage];
return newannotationview;
}
return nil;
}
This is changing the view you defined into a picture.
-(UIImage *) Getimagefromview: (UIView *) view{
Uigraphicsbeginimagecontext (view.bounds.size);
[View.layer Renderincontext:uigraphicsgetcurrentcontext ()];
UIImage *image = Uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();
return image;
}
iOS growth path Baidu map Overlay