Provides various official and user-released code examples and code reference. You are welcome to share the source code of Baidu geographic location.
Implement Baidu Positioning
1. Use APIclound IDE To create a project named positioning:
2. log on to the official APIclound website and go to your own console. The application name is displayed:
3, use your own Baidu Account Login Baidu Open Platform: http://lbsyun.baidu.com/apiconsole/key? Application = key application key
How to obtain the digital signature and package name:
Apple uses a security code.
After obtaining the accesskey, The accesskey is used as the key.
4. Add Baidu sdk to config. xml:
5,
6,
7,
8,
9. main.html
10. var baiduLocation = api. require ('baidulocation ');
11. baiduLocation. getLocation (function (ret, err ){
12. var sta = ret. status;
13. var lat = ret. latitude;
14. var lon = ret. longpolling;
15. var t = ret. timestamp;
16. if (sta ){
17. var str1 = 'longitude: '+ lon +'
';
18. str1 + = 'latitude: '+ lat +'
';
19. str1 + = 'Update time: '+ t +'
';
20. api. alert ({
21. msg: str1
22 ,});
23. var map = api. require ('baidumap ');
24. map. getNameFromLocation ({
25. lon: lon,
26. lat: lat
27,}, function (ret, err ){
28. if (ret. status ){
29. var dizhi = ret. province + ret. city + ret. district + ret. streetName + ret. streetNumber;
30. str1 + ='
Current geographic location: '+ dizhi +'
';
31. api. alert ({
32. title: 'search result ',
33. msg: dizhi
34 ,});
35. str1 + ='';
36. $ api. byId ('sys-info1'). innerHTML = str1;
37,
38. // upload the address to the server
39. api. ajax ({
40. url: 'http: // 192.168.1.52/upLoad/aaa. php ',
41. method: 'post ',
42. timeout: 30,
43. dataType: 'json ',
44. returnAll: false,
45. data :{
46. values :{
47. dizhi: dizhi,
48. lon: lon,
49. lat: lat,
50, t: t
51 ,},
52,
53 ,}
54,}, function (ret, err ){
55. if (ret ){
56. varurlJson = JSON. stringify (ret );
57. varmyobj = eval (ret );
58. api. alert ({
59. msg: urlJson
60 ,});
61. api. alert ({
62. msg: myobj [0] ['dizhi'] // correct.
63 ,});
64,} else {
65. api. alert ({
66. msg: ('error code: '+ err. code +'; error message: '+ err. msg +' network status code: '+ err. statusCode)
67 ,});
68 ,};
69 ,});
70 ,/*********************/
71,
72,} else {
73. api. alert ({
74. title: 'search error Code ',
75. msg: err. msg
76 ,});
77 ,}
78 ,});
79. // display position
80,} else {
81. api. alert ({
82. msg: err. msg
83 ,});
84 ,}
85 ,});
86,
87,
88,
Php code:
$ Dizhi = $ _ POST ["dizhi"];
$ Lon = $ _ POST ["lon"];
$ Lat = $ _ POST ["lat"];
$ T = $ _ POST ["t"];
$ Str = $ dizhi. "\ r \ n ". $ lon. "\ r \ n ". $ lat. "\ r \ n ". $ t. "\ r \ n ";
$ Open = fopen ("log.txt", "");
Fwrite ($ open, $ str );
Fclose ($ open );
$ Json [] = $ _ POST;
Echo json_encode ($ json );
?>
Http://community.apicloud.com/bbs/forum.php? Mod = viewthread & tid = 7890.
Positioning .rar (306.31 KB download: 74 times)
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB