baidu_map_frm.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
  6. <title>APP</title>
  7. <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
  8. </head>
  9. <style type="text/css">
  10. body {
  11. background-color: #ffffff;
  12. }
  13. </style>
  14. <body>
  15. </body>
  16. <script type="text/javascript" src="../../../script/api.js" ></script>
  17. <script type="text/javascript">
  18. var winHeight,
  19. map,
  20. lat='39.989539',
  21. lon='116.384767';
  22. apiready = function(){
  23. winHeight = api.pageParam.height;
  24. api.parseTapmode();
  25. map = api.require('bMap');
  26. getLocation();
  27. open();
  28. };
  29. //打开地图
  30. function open(){
  31. map.open({
  32. rect: {
  33. x: 0,
  34. y: winHeight,
  35. w: 'auto',
  36. h: api.frameHeight
  37. },
  38. center: {
  39. lon: lon,
  40. lat: lat
  41. },
  42. zoomLevel: 15,
  43. showUserLocation: true,
  44. fixedOn: '',
  45. fixed: true
  46. }, function(ret){
  47. });
  48. }
  49. //关闭
  50. function close(){
  51. map.close();
  52. }
  53. //显示
  54. function show(){
  55. map.show();
  56. }
  57. //隐藏
  58. function hide(){
  59. map.hide();
  60. }
  61. //初始化
  62. function restart(){
  63. api.toast({
  64. msg: '请稍候',
  65. duration:1500,
  66. location: 'top'
  67. });
  68. setTimeout(function(){
  69. close();
  70. open();
  71. },1000)
  72. }
  73. //获取坐标
  74. function getLocation(){
  75. map.getLocation({
  76. accuracy: '100m',
  77. autoStop: true,
  78. filter: 1
  79. }, function(ret, err){
  80. if(ret.status){
  81. lat = ret.lat;
  82. lon = ret.lon;
  83. alert(JSON.stringify(ret));
  84. }else{
  85. alert(err.code);
  86. }
  87. });
  88. }
  89. //根据地址查找坐标
  90. function getCoordsFromName(){
  91. api.showProgress({
  92. style: 'default',
  93. animationType: 'fade',
  94. title: '定位中...',
  95. text: '请稍候...',
  96. modal: false
  97. });
  98. map.getCoordsFromName({
  99. city: '北京',
  100. address: '天安门'
  101. },function(ret,err){
  102. api.hideProgress();
  103. if(ret.status){
  104. alert(JSON.stringify(ret));
  105. }
  106. });
  107. }
  108. /*
  109. *根据坐标查找地址
  110. *获取我的坐标地址
  111. */
  112. function getNameFromCoords(){
  113. api.showProgress({
  114. style: 'default',
  115. animationType: 'fade',
  116. title: '定位中...',
  117. text: '请稍候...',
  118. modal: false
  119. });
  120. map.getNameFromCoords({
  121. lon: lon,
  122. lat: lat
  123. },function(ret,err){
  124. api.hideProgress();
  125. if(ret.status){
  126. alert(JSON.stringify(ret));
  127. }
  128. });
  129. }
  130. /*
  131. *两点距离
  132. */
  133. function getDistance(){
  134. api.showProgress({
  135. style: 'default',
  136. animationType: 'fade',
  137. title: '定位中...',
  138. text: '请稍候...',
  139. modal: false
  140. });
  141. map.getDistance({
  142. start: {
  143. lon: lon,
  144. lat: lat
  145. },
  146. end: {
  147. lat: 39.915174,
  148. lon: 116.403901
  149. }
  150. },function(ret){
  151. api.hideProgress();
  152. if(ret.status){
  153. alert("距离天安门约:"+ret.distance+"米");
  154. }
  155. });
  156. }
  157. /*
  158. *setCenter
  159. *设置地图中心点
  160. */
  161. function setCenter(){
  162. api.toast({
  163. msg: '定位中',
  164. duration:1500,
  165. location: 'top'
  166. });
  167. map.setCenter({
  168. coords: {
  169. lon: lon,
  170. lat: lat
  171. },
  172. animation:false
  173. });
  174. }
  175. /*
  176. *showUserLocation
  177. *显示用户位置
  178. */
  179. function showUserLocation(){
  180. api.toast({
  181. msg: '定位中',
  182. duration:1500,
  183. location: 'top'
  184. });
  185. map.showUserLocation({
  186. isShow: true,
  187. trackingMode: 'none'
  188. });
  189. //缩放一下
  190. setZoomLevel();
  191. }
  192. /*
  193. *setZoomLevel
  194. *设置缩放等级
  195. */
  196. function setZoomLevel(){
  197. map.setZoomLevel({
  198. level: 18
  199. });
  200. }
  201. /*
  202. *setRotation
  203. *设置旋转角度
  204. */
  205. function setRotation(){
  206. map.setRotation({
  207. degree: 90
  208. });
  209. }
  210. /*
  211. *setOverlook
  212. *设置俯视角度
  213. */
  214. function setOverlook(){
  215. map.setOverlook({
  216. degree: -30
  217. });
  218. }
  219. /*
  220. *setScaleBar
  221. *比例尺
  222. */
  223. function setScaleBar(){
  224. map.setScaleBar({
  225. show: true,
  226. position: {
  227. x:0,
  228. y:0
  229. }
  230. });
  231. }
  232. /*
  233. *setCompass
  234. *指南针位置
  235. */
  236. function setCompass(){
  237. map.setCompass({
  238. position: {
  239. x:50,
  240. y:50
  241. }
  242. });
  243. }
  244. /*
  245. *setTraffic
  246. *交通路况
  247. */
  248. function setTraffic(){
  249. map.setTraffic({
  250. traffic: true
  251. });
  252. }
  253. /*
  254. *setHeatMap
  255. *设置当前城市为热力图
  256. */
  257. function setHeatMap(){
  258. map.setHeatMap({
  259. heatMap: true
  260. });
  261. map.setZoomLevel({
  262. level: 13
  263. });
  264. }
  265. /*
  266. *setBuilding
  267. *是否显示3d
  268. */
  269. function setBuilding(){
  270. map.setBuilding({
  271. building: true
  272. });
  273. alert('设置成功,放大地图查看效果');
  274. }
  275. /*
  276. *setRegion
  277. *设置地图显示范围(矩形区域)
  278. */
  279. function setRegion(){
  280. map.setRegion({
  281. lbLon: 116.027143,
  282. lbLat: 39.772348,
  283. rtLon: 116.832025,
  284. rtLat: 40.126349,
  285. animation: true
  286. });
  287. }
  288. /*
  289. *transCoords
  290. *坐标转换
  291. */
  292. function transCoords(){
  293. alert('注意该方法需要重写加入mcode');
  294. map.transCoords({
  295. type: "common",
  296. lon: 116.351,
  297. lat: 39.283,
  298. mcode: '0B:13:25:D7:85:46:0A:67:12:F3:29:88:64:56:63:10:7A:9C:C4:59;com.apicloud.A6985734480360'
  299. }, function(ret, err){
  300. alert(JSON.stringify(ret));
  301. });
  302. }
  303. /*
  304. *addEventListener
  305. *监听事件
  306. */
  307. function addEventListener(){
  308. alert("将会监听地图双击事件,请双击地图");
  309. map.addEventListener({
  310. name: 'dbclick'
  311. },function(ret){
  312. if(ret.status){
  313. alert(JSON.stringify(ret));
  314. }
  315. });
  316. }
  317. /*
  318. *停止监听
  319. */
  320. function removeEventListener(){
  321. map.removeEventListener({
  322. name: 'dbclick'
  323. });
  324. alert("已取消监听双击事件");
  325. }
  326. /*
  327. *addAnnotations
  328. *添加标注信息
  329. */
  330. function addAnnotations(){
  331. alert("该方法封装了标注点击弹出气泡");
  332. map.addAnnotations({
  333. annotations: [{
  334. id: 1, lon: 116.297, lat: 40.109
  335. },
  336. {
  337. id: 2, lon: 116.29, lat: 40.109
  338. },
  339. {
  340. id: 3, lon: 116.298, lat: 40.11
  341. }],
  342. icon: 'widget://image/mark.png',
  343. draggable: true
  344. }, function(ret){
  345. if(ret){
  346. //设置点击标注时弹出的气泡信息
  347. map.setBubble({
  348. id: ret.id,
  349. bgImg: 'widget://image/mapbg.png',
  350. content: {
  351. title: '标注'+ret.id,
  352. subTitle: '这是第'+ret.id+'个标注',
  353. illus: 'widget://image/liulangnan2.jpg'
  354. },
  355. styles: {
  356. titleColor: '#009900',
  357. titleSize: 14,
  358. subTitleColor: '#999',
  359. subTitleSize: 12,
  360. illusAlign: 'left'
  361. }
  362. }, function(ret){
  363. if(ret){
  364. alert(JSON.stringify(ret));
  365. }
  366. });
  367. }
  368. });
  369. map.setCenter({
  370. coords: {
  371. lon: 116.297,
  372. lat: 40.109
  373. },
  374. animation:false
  375. });
  376. }
  377. /*
  378. *addBillboard
  379. *添加布告牌
  380. */
  381. function addBillboard(){
  382. //设置下中心点
  383. setCenter();
  384. map.addBillboard({
  385. id: 4,
  386. coords: {
  387. lon: lon,
  388. lat: lat
  389. },
  390. bgImg: 'widget://image/mapbg2.png',
  391. content: {
  392. title: '大标题大标题大标题大标题',
  393. subTitle: '概述内容概述内容概述内容',
  394. illus: 'widget://image/liulangnan2.jpg'
  395. },
  396. styles: {
  397. titleColor: '#009900',
  398. titleSize: 14,
  399. subTitleColor: '#999',
  400. subTitleSize: 12,
  401. illusAlign: 'left'
  402. }
  403. }, function(ret){
  404. if(ret){
  405. alert(JSON.stringify(ret));
  406. }
  407. });
  408. }
  409. /*
  410. *searchRoute
  411. *搜索路线方案
  412. */
  413. function searchRoute(){
  414. api.showProgress({
  415. style: 'default',
  416. animationType: 'fade',
  417. title: '搜索中...',
  418. text: '请稍候...',
  419. modal: false
  420. });
  421. map.searchRoute({
  422. id: 1,
  423. type: 'drive',
  424. policy: 'ecar_fee_first',
  425. start: {
  426. lon: 116.403838,
  427. lat: 39.914437
  428. },
  429. end: {
  430. lon: 116.384852,
  431. lat: 39.989576
  432. }
  433. }, function(ret, err){
  434. if(ret.status){
  435. api.alert({msg:JSON.stringify(ret)});
  436. drawRoute(1);
  437. }
  438. api.hideProgress();
  439. });
  440. }
  441. /*
  442. *绘制路线(安卓)
  443. */
  444. function drawRoute(id){
  445. map.searchRoute({
  446. type: 'drive',
  447. policy: 'ecar_fee_first',
  448. start: {
  449. lon: 116.403838,
  450. lat: 39.914437
  451. },
  452. end: {
  453. lon: 116.384852,
  454. lat: 39.989576
  455. }
  456. }, function(ret, err){
  457. if(ret.status){
  458. map.drawRoute({
  459. id: id,
  460. index: 0,
  461. styles: {
  462. start: {
  463. icon: 'widget://image/mark_start.png'
  464. },
  465. end: {
  466. icon: 'widget://image/mark_end.png'
  467. }
  468. }
  469. }, function(ret){
  470. api.alert({msg:JSON.stringify(ret)});
  471. });
  472. } else {
  473. api.alert({msg:JSON.stringify(err)});
  474. }
  475. });
  476. }
  477. /*移除指定的路线*/
  478. function removeRoute(){
  479. map.removeRoute({
  480. ids: [1]
  481. });
  482. }
  483. /*
  484. *searchInCity
  485. *根据单个关键字搜索兴趣点
  486. */
  487. function searchInCity(){
  488. api.showProgress({
  489. style: 'default',
  490. animationType: 'fade',
  491. title: '搜索中...',
  492. text: '请稍候...',
  493. modal: false
  494. });
  495. map.searchInCity({
  496. city: '北京',
  497. keyword: '学校',
  498. pageIndex: 0,
  499. pageCapacity: 20
  500. },function(ret){
  501. api.hideProgress();
  502. if(ret.status){
  503. alert(JSON.stringify(ret.results));
  504. var results = ret.results;
  505. for(var i in results){
  506. map.addAnnotations({
  507. annotations: [{
  508. id: results[i].uid,
  509. lon: results[i].lon,
  510. lat: results[i].lat
  511. }],
  512. icon: 'widget://image/mark.png',
  513. draggable: true
  514. }, function(ret){
  515. if(ret){
  516. }
  517. });
  518. }
  519. map.setCenter({
  520. coords: {
  521. lon: results[1].lon,
  522. lat: results[1].lat
  523. },
  524. animation:false
  525. });
  526. }else{
  527. alert(JSON.stringify(err));
  528. }
  529. });
  530. }
  531. /*
  532. *searchNearby
  533. *圆形区域内搜索兴趣点
  534. */
  535. function searchNearby(){
  536. map.searchNearby({
  537. keyword: 'KTV',
  538. lon: 116.384767,
  539. lat: 39.989539,
  540. radius: 2000
  541. },function(ret,err){
  542. if(ret.status){
  543. alert(JSON.stringify(ret));
  544. }else{
  545. alert(JSON.stringify(err));
  546. }
  547. });
  548. }
  549. /*
  550. *autocomplete
  551. *根据关键字返回建议搜索关键字
  552. */
  553. function autocomplete(){
  554. map.autocomplete({
  555. keyword: '北京西站',
  556. city: '北京'
  557. },function(ret){
  558. if(ret.status){
  559. alert(JSON.stringify(ret.results));
  560. }else{
  561. alert(JSON.stringify(err));
  562. }
  563. });
  564. }
  565. </script>
  566. </html>