before the Baidu Map API development, you need to http://developer.baidu.com/map Application key
After the application of the key can be Baidu Map API development.
Let's take a map coordinate notation in visual c++6.0 to illustrate Baidu map API development
1. Create a new factory MFC project named Geodemo
2. Select the project that is based on the dialog box
3. Create success as follows
4. Simply adjust the page layout
5. Insert a browser control in the interface
6. Effects after insertion
7. Run it first and see
8. Next we write a simple HTML page, the code is probably the following
It also includes a JavaScript function, which will not be written for reference http://developer.baidu.com/map/jsdemo.htm#a1_2
We name this HTML file geodemo.html and put it in the project directory:
The HTML source code is:
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <Metahttp-equiv= "Content-type"content= "text/html; charset=gb2312" />5 <styletype= "Text/css">6 body, HTML, #allmap {width:100%;height:100%;overflow:hidden;margin:0;}7 #l-map{height:100%;width:78%;float:left;border-right:2px solid #bcbcbc;}8 #r-result{height:100%;width:20%;float:left;}9 </style>Ten <Scripttype= "Text/javascript"src= "http://api.map.baidu.com/api?v=2.0&ak= The key you apply for yourself"></Script> One <title>Baidu Map of Hello, world</title> A </Head> - <Body> - <DivID= "Allmap"></Div> the </Body> - </HTML> - <Scripttype= "Text/javascript"> - var map = new Bmap.map ("Allmap"); + Map.centerandzoom (New Bmap.point (104.071216,30.666031), n); - Map.enablescrollwheelzoom (); Enable wheel zoom in and zoom out + Map.addcontrol (New Bmap.navigationcontrol ()); A Map.addcontrol (New Bmap.overviewmapcontrol ()); at Map.addcontrol (New Bmap.scalecontrol ()); - Map.enablescrollwheelzoom (); - Map.addcontrol (New Bmap.maptypecontrol ()); - - var top_left_navigation = new Bmap.navigationcontrol (); Upper left corner, add default zoom translation control - in - function Justmarkfun (JD,WD) to { + var marker1 = new Bmap.marker (new Bmap.point (JD,WD)); Create a callout - Window.map.addOverlay (Marker1); Add a callout to a map the } * </Script>
Of course, some of the properties can be referred to the Baidu Map API instructions to write, I use the JavaScript version of the public
You can choose different types of APIs according to your needs.
Here I will map the initial center of the location in Chengdu, about the latitude and longitude of the query can be to the site: http://api.map.baidu.com/lbsapi/getpoint/index.html
9. We continue to associate a control variable to m_myweb for the browser Control of the dialog box
Of course, you will also be prompted to add the CWebBroswer2 class header file and source file
10. Add a response to show this point
11. Add the following code in the OnInitDialog () function of Cgeodemodlg:
Note that the HTML file is to be URL-
. Import the Cwebpage class, which provides a JavaScript interface for C + +
Let's see a cwebpage. A simple interface Description:
1 BOOL Calljscript (const CString strfunc,const CString strArg1,const CString strarg2,ccomvariant * Pvarresult = NULL);
The first parameter represents the function name of the JS function to invoke
The second third parameter represents the parameter to be passed in, and obviously we should say longitude and latitude are passed into it
The last one is the return value of the JS call
13. Include the webpage.h header file in the CGeoDemoDlg.cpp and Add the following code in OnShow ():
Here M_jd and M_WD are two CString type variables with the edit box control, passing in longitude latitude values
The number of arguments here is the same as the number of JavaScript function Justmakefun functions, and the order
To remain consistent
The JavaScript code is as follows:
1 function Justmarkfun (JD,WD) 2 {3 var New Bmap.marker (new bmap.point (JD,WD)); // Create a callout 4 Window.map.addOverlay (marker1); // add a callout to a map 5 }
To write other functions of the JS function reference Baidu Map API corresponding interface reference
14. Now we find the coordinates of the Sichuan 104.089038,30.638195 in the coordinate pickup tool.
Input to latitude and longitude and execute:
Done!
About demo source contact me [email protected]
Example of Baidu Map API development based on MFC and third party class Cwebpage