iOS Baidu Map API develop custom bubbles, click the Bubble auto-generated route, and drag
iOS Baidu Map Development Poisearch Search nearby parking, nearby gas station
iOS Baidu map view jump to the user's current location
iOS Baidu Map Development real-time traffic
iOS Development Baidu Map Auto-navigation
iOS Development Baidu Map add text and pictures on the nails, click on the whole and then pop bubbles
iOS development Baidu Map to achieve latitude navigation, no place names.
The first part--kind
Baidu maps 0 base to various effects interface. The above a few lines do not see, that is to SEO, is to let me this blog to let more people search, the above problems I have solved, are in the article. Here are the steps:
1. apply for Baidu map key. 2.1. Version 0 after October 2013 start new key! to use the Baidu map, you need to apply for key, this key is an Apple universal, but your project name must match your key, as to what is the project name, not much to say, to the URL http://lbsyun.baidu.com/apiconsole/key application ,
My app
App ID |
App Name |
Access Application (AK) |
Application Category |
Note Information (double-click changes) |
application Configuration |
System default AK |
System default AK |
aa1********28e |
Not Configured |
AK used by the current system |
AK used by the current system |
17673 |
Iphonemapsdkdemo |
pytxh1exmzkaneo5vf4k |
Mobile side |
|
Set Delete |
17721 |
Maptest |
lqwusezrojwxwb2zz4e |
Mobile side |
|
Set Delete |
2.Download Baidu Development Kit,Http://api.map.baidu.com/lbsapi/cloud/sdkiosdev-download.htm,
3. Build the project. This part of the design to add Lib and resource files, reference Baidu's iOS API Development Guide to do the line, those content has been updated in October 2013, do not go to see the online mess of the post, as the inside can be successfully compiled. There are posts saying that those methods are outdated, wrong!
4.change the Viewcontroller. M to. mm
5.In the . h file in the delegate.Add the #import "BMapKit.h" and declare the variable bmkmapmanager* _mapmanager; join in the. M delegate
_ Mapmanager = [[Bmkmapmanager alloc]init];
If you want to focus on network and authorization validation events, set the Generaldelegate parameter
BOOL ret = [_mapmanager start:@ "3102732b30e0d66ef51415c9e6ce055ec78ff07e" generaldelegate:nil];
if (!ret) {
NSLog (@ "manager start failed!");
}
6.Note:Start running the program here, I run this Baidu map on my iphone, will appear-[uidevice Uniqueglobaldeviceidentifier]: Unrecognized selector sent to instance 0x1ed19370
Such a bug, a lot of solutions, but I feel the most cool way is to add 4 files nsstring+md5addition,uidevice+identifieraddition, directly into the project can be, without the introduction of header files, HTTP ://www.kuaipan.cn/file/id_30491149655344975.htm
7.in the viewcontroller.mmChange the viewdidload to the following code
-(void) viewdidload
{
[Super Viewdidload];
bmkmapview* Mapview = [[Bmkmapview alloc]initwithframe:cgrectmake (0, 0, 320, 548)];
Self.view = Mapview;
Additional setup after loading the view, typically from a nib.
}
After the save run, one of the simplest Baidu maps API application is completed
Source code Download http://www.kuaipan.cn/file/id_30491149655344976.htm
The function of Baidu map is very powerful, above just kind
Part II
functionFive, search, with a wide range of, this feature is very powerful, you can search for a certain punctuation near the gas station, parking lot, hotel, hotel, restaurant, even the toilet can be found, for example, you want to find a 5000 meters inside the gas station, as well as the parking lot within 1000 meters.
Flag = [_search poisearchnearby:@ "Petrol station" Center:coor1 radius:5000 pageindex:0];
Flag = [_search poisearchnearby:@ "parking lot" Center:coor1 radius:1000 pageindex:0];
Then use the delegate-(void) Ongetpoiresult: (nsarray*) poiresultlist searchtype: (int) type errorCode: (int) error
Output results.
Switch Baidu Map view to a certain sitting punctuation
-(void) region{
Cllocationcoordinate2d coor;
Coor.latitude = Self._latitude;
Coor.longitude = Self._longitude;
Nsdictionary *tip = BMKBaiduCoorForWgs84 (coor);
Cllocationcoordinate2d coor1= Bmkcoordictionarydecode (TIP);
Bmkcoordinateregion viewregion = Bmkcoordinateregionmake (Coor1, Bmkcoordinatespanmake (0.05,0.05));
Bmkcoordinateregion adjustedregion = [_mapview regionthatfits:viewregion];
[_mapview setregion:adjustedregion Animated:yes];
}
clear all traces and routes on the map
-(void) clereoldyjdh{
nsarray* array = [Nsarray arraywitharray:_mapview.annotations];
[_mapview Removeannotations:array];
Array = [Nsarray arraywitharray:_mapview.overlays];
[_mapview Removeoverlays:array];
[Self region];
}
//When a annotation views is selected, this interface is called
-(void) Mapview: (Bmkmapview *) Mapview Didselectannotationview: (Bmkannotationview *) view
{
NSLog (@ "Select a annotation views:%f,%f", view.annotation.coordinate.latitude,view.annotation.coordinate.longitude);
}
//This interface is called when a annotation views is unchecked
-(void) Mapview: (Bmkmapview *) Mapview Diddeselectannotationview: (Bmkannotationview *) view{
NSLog (@ "Uncheck a annotation views");
}
//This interface is called when Mapview new annotation views are added
-(void) Mapview: (Bmkmapview *) Mapview didaddannotationviews: (Nsarray *) views
{
NSLog (@ "Mapview newly added annotation views");
}
//call this interface when you click Annotation View pop-up bubble
-(void) Mapview: (Bmkmapview *) Mapview annotationviewforbubble: (Bmkannotationview *) view
{
NSLog (@ "Click Annotation View pop-up bubble");
}
//change the state of view when dragging annotation view
-(void) Mapview: (Bmkmapview *) Mapview Annotationview: (Bmkannotationview *) View didchangedragstate: ( Bmkannotationviewdragstate) Newstatefromoldstate: (bmkannotationviewdragstate) oldstate
{
NSLog (@ "Dynamic annotation View state change");
}
//callout Green style studs
((Bmkpinannotationview *) annotationview). Pincolor = Bmkpinannotationcolorgreen;
//allow user to drag
[Annotationview Setdraggable:yes];
//view that appears on the left side of the bubble box and can be customized
Annotationview.leftcalloutaccessoryview = [[Uiimageview alloc] initwithimage:[uiimage imagenamed:@ "Icon_ Location.png "];
//view customizable on the right side of the bubble box
Annotationview.rightcalloutaccessoryview =selectbutton;
//the status of the pop-up bubble box when the callout enters the interface
[Annotationview Setselected:yes Animated:yes];
The offset of the entire callout
Annotationview.centeroffset = Cgpointmake (0,-(annotationView.frame.size.height * 0.5));
Annotationview.annotation = punctuation latitude and longitude of annotation;//bindings
Annotationview.canshowcallout = true;//allows you to click the Pop-up bubble box
Customize labels on the map to replace the head nails, you can add the text picture all can be added to the view, can be shown in the form of a head nail, you need to convert the view to the image main code, the most important thing is to know the principle, and then the implementation is very simple:
-(Bmkannotationview *) Mapview: (Bmkmapview *) View viewforannotation: (id <BMKAnnotation>) annotation
Implement the following code in this delegate
UIView *viewforimage=[[uiview alloc]initwithframe:cgrectmake (0, 0, 132, 64)];
Uiimageview *imageview=[[uiimageview alloc]initwithframe:cgrectmake (0, 0, 32, 64)];
[ImageView setimage:[uiimage imagenamed:@ "car location. png"]];
[Viewforimage Addsubview:imageview];
UILabel *label=[[uilabel Alloc]initwithframe:cgrectmake (32, 0, 100, 64)];
[Email protected] "Chen Dishu";
Label.backgroundcolor=[uicolor Clearcolor];
[Viewforimage Addsubview:label];
Annotationview.image=[self Getimagefromview:viewforimage];
-(UIImage *) Getimagefromview: (UIView *) view{
Uigraphicsbeginimagecontext (view.bounds.size);
[View.layer Renderincontext:uigraphicsgetcurrentcontext ()];
UIImage *image = Uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();
return image;
}
Find someone who specializes in creating a view on the web to customize the bubbles and create files specifically to customize the spikes, feeling that the method is simpler and more readable for code management. Worth Learning http://www.kuaipan.cn/file/id_30491149655345085.htm
@interface Kybubbleview:uiscrollview {//uiview is the essence of bubble view
Nsdictionary *_infodict;
UILabel *titlelabel;//Title Label
UILabel *detaillabel;//Subtitle Label
UILabel *contactlabel; Contact
UILabel *homeaddresslabel; Home Address
UIButton *rightbutton;
Nsuinteger index;
}
#import "BMKPointAnnotation.h"
@interface Kypointannotation:bmkpointannotation {
Nsuinteger _tag;
}
@property Nsuinteger tag;
@end
Part
Part III
1. A friend asked me when he did the navigation, transmission parameters encountered problems, that is, the input of the Chinese character part is not,how to achieve route navigation by two-point latitude and longitude, he tried for a long time not to get out. Then I post the source code to solve the problem. I do the driving route and I need to make adjustments if I need to walk or take a bus. The main approach involved is to implement this code, which I get directly out of my project http://www.kuaipan.cn/file/id_30491149655345069.htm
-(void) Onclickdrivesearch
{
NSLog (@ "%f,%f,%f,%f", _startcoordainatextext,_startcoordainateytext,_endcoordainatextext,_endcoordainateytext);
Count = 0;
isloadingmap=2;
if (!_endcoordainatextext | |! _endcoordainateytext) Isloadingmap=1;
nsarray* array = [Nsarray arraywitharray:_mapview.annotations];
[_mapview Removeannotations:array];
Array = [Nsarray arraywitharray:_mapview.overlays];
[_mapview Removeoverlays:array];
Cllocationcoordinate2d startpt = (cllocationcoordinate2d) {0, 0};
Cllocationcoordinate2d ENDPT = (cllocationcoordinate2d) {0, 0};
if (_startcoordainatextext && _startcoordainateytext) {
STARTPT = (cllocationcoordinate2d) {_startcoordainateytext, _startcoordainatextext};
}
if (_endcoordainateytext && _endcoordainatextext) {
ENDPT = (cllocationcoordinate2d) {_endcoordainateytext, _endcoordainatextext};
}
bmkplannode* start = [[Bmkplannode alloc]init];
start.pt = STARTPT;
Start.name = nil;
bmkplannode* end = [[Bmkplannode alloc]init];
end.pt = ENDPT;
End.name = nil;
BOOL flag = [_search drivingsearch:nil startnode:start Endcity:nil endnode:end];
if (!flag) {
NSLog (@ "search failed");
}
[Start release];
[End release];
[Self region];
}
Related articles:
Open platform: Baidu maps for IOS use related
ios-Baidu Map API with point generation lines, navigation, custom labeling November 2013 update