IOS Baidu map API Environment Construction

Source: Internet
Author: User

1 Preface
Due to work needs, it is necessary to start to smash the Baidu map. This morning, we started to take a nap at noon and made great efforts to prepare for the three hundred round of the afternoon war, fortunately, the Baidu map demo was released at noon this afternoon. I would like to share with you the environment building tutorial, dedicated to cainiao, so do not spray it!

This article aims to help beginners quickly build Baidu map for iOS. There are tutorials on the official website, but it is too old. Now xcode is updated to 4.6. His tutorial should be before 4.3. It is estimated that new users will encounter errors when building them. Follow the steps in my tutorial to make sure that you spend the least time developing maps quickly.

Machine environment: Mac OS X 10.8.2
Development Environment: xcode4.6
Real machine environment: IPOD touch4g version: 6.1.2

[Note]: to use the Baidu map SDK, you need to apply for a key. The application name can be written at will, provided that you have a Baidu account. For details, refer to the official website.


2. Details
2.1 Official website download the latest SDK _ IOS static library file http://developer.baidu.com/map/sdkiosdev-download.htm
After decompression, as shown in:

 

 
 

2.2 Open xcode, create a demo project (or under your existing project), and create the downloaded Inc, Libs, and mapapi. the three bundle folders are imported into the project. Note that copy + destination is required. See the following:

 

 
 

Make sure to select copy and create group and add them to target at the same time.


2.3 almost all third-party map sdks depend on Apple's own frameworks. Therefore, we need to import corelocation. Framework and quartzcore. framework in this step. The import method is as follows:

 
 

 

Zookeeper ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If. h imports the bmapkit. h header file and instantiates bmkmapmanager or bmapview, the following error will occur:

 

 
 

It seems that libbaidumapapi. A cannot be found. Is it a path problem? This is a common bmkmapmanager error. The principle is that the system cannot link to our static Map Library. The solution is as follows:
Zookeeper -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


2.4 The above is a small attempt and an episode. Let's proceed to the next step, select the project, target, switch to the build setting tag, and locate the other link flag,
Input:-all_load

 

 
 

2.5 now you need to set the environment variables of the Linked Library so that the project can find the environment variables in the directory smoothly. file a, select the project and target, switch to the build setting tag, and locate the library search path, as shown in:

 
 

 

Delete the three existing ones and add one (simulator + real machine): $ (srcroot)/libs/release $ (effective_platform_name)
A brief explanation:
$ (Srcroot) macro represents your project file directory. $ (effective_platform_name) macro represents whether the current configuration is OS or simulator. I do not know much about the environment variables, I tried it myself. You just copy this line. As follows:

 

 
 

2.6 At this time, the static library file has been set up, and the rest is only code work. Because key verification is required, we need to first use the bmkmapmanager class to configure the applied key, to get authorization. Select appdelegate. h

 

[Plain] # import "bmapkit. H" // import bmapkit. h
 
@ Interface appdelegate: uiresponder <uiapplicationdelegate> {
Bmkmapmanager * _ mapmanager; // instantiate
}

# Import "bmapkit. H" // import bmapkit. h

@ Interface appdelegate: uiresponder <uiapplicationdelegate> {
Bmkmapmanager * _ mapmanager; // instantiate
} Select appdelegate. m, change. mm, (note: objectc ++ is used in the static library. Therefore, you must ensure that at least one of your projects exists. MM suffix source file (you can set any one. the file with the m suffix is renamed. mm ))
[NOTE: If there is no mm, a large number of errors will be reported during running]
Add the following code to didfinishlaunchingwitexceptions in appdelegate. mm:
[Plain]-(bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary *) launchoptions
{
// To use Baidu map, start baidumapmanager first
_ Mapmanager = [[bmkmapmanager alloc] init];
// If you want to pay attention to network and authorization verification events, set the generaldelegate parameter.
Bool ret = [_ mapmanager start: @ "3830003d1dafe904d7226e48f2f488262d5b23d2" generaldelegate: Nil];
If (! RET ){
Nslog (@ "Manager Start failed! ");
}
Self. Window = [[[uiwindow alloc] initwithframe: [[uiscreen mainscreen] bounds] autorelease];
// Override point for customization after application launch.
Self. viewcontroller = [[[zyviewcontroller alloc] initwithnibname: @ "zyviewcontroller" Bundle: Nil] autorelease];
Self. Window. rootviewcontroller = self. viewcontroller;
[Self. Window makekeyandvisible];
Return yes;
}

-(Bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary *) launchoptions
{
// To use Baidu map, start baidumapmanager first
_ Mapmanager = [[bmkmapmanager alloc] init];
// If you want to pay attention to network and authorization verification events, set the generaldelegate parameter.
Bool ret = [_ mapmanager start: @ "3830003d1dafe904d7226e48f2f488262d5b23d2" generaldelegate: Nil];
If (! RET ){
Nslog (@ "Manager Start failed! ");
}
Self. Window = [[[uiwindow alloc] initwithframe: [[uiscreen mainscreen] bounds] autorelease];
// Override point for customization after application launch.
Self. viewcontroller = [[[zyviewcontroller alloc] initwithnibname: @ "zyviewcontroller" Bundle: Nil] autorelease];
Self. Window. rootviewcontroller = self. viewcontroller;
[Self. Window makekeyandvisible];
Return yes;
}
2.7 Add the following code to viewcontroller. m to display the map:


[Plain] # import "viewcontroller. H"
# Import "bmkmapview. H"
 
@ Interface viewcontroller ()
 
@ End
 
@ Implementation viewcontroller
 
-(Void) viewdidload
{
[Super viewdidload];
Bmkmapview * mapview = [[bmkmapview alloc] initwithframe: cgrectmake (0, 0,320,460)];
Self. view = mapview;
}

# Import "viewcontroller. H"
# Import "bmkmapview. H"

@ Interface viewcontroller ()

@ End

@ Implementation viewcontroller

-(Void) viewdidload
{
[Super viewdidload];
Bmkmapview * mapview = [[bmkmapview alloc] initwithframe: cgrectmake (0, 0,320,460)];
Self. view = mapview;
}
After importing bmkmapview. H, instantiate the bmkmapview class.


2.8 After authorization in appdelegate, mapview can be used in any viewcontroller at will.
(Of course, bmkmapmanager authorization can also be written to any viewcontroller, but in this case, mapview can only be used in this viewcontroller. If map is used for other classes, authorization is required again, otherwise, the map view will be black ):


Real machine:

 

Related Article

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.