Baidu Map API, according to latitude and longitude to achieve vehicle movement trajectory mapping

Source: Internet
Author: User
Tags polyline

Baidu Map, to achieve vehicle trajectory mapping

Implementation ideas:

1. Vehicle trajectory mapping according to latitude and longitude

2. Using the Baidu Map API two overlay implementation, Polyline (polyline) Draw track, Marker (icon) to draw the car icon

3. Connect each of the two coordinates to form a coherent trajectory line

4. After the next icon is generated, delete the last drawn icon to create a car moving animation sense

5. This example uses an adjacent random coordinate point

6. Beginners, welcome everyone to exchange study

7. View the instance

Code:

[HTML]View PlainCopy 
  1. <! DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv= "content-type" content= "text/html; Charset=utf-8 " />
  5. <meta name="viewport" content="initial-scale=1.0, User-scalable=no" />
  6. <style type="Text/css">
  7. Body, HTML, #allmap {width:100%;height:100%;overflow:hidden;margin:0;font-family: "Microsoft Jas Black";}
  8. </style>
  9. <script type="Text/javascript" src= "http://api.map.baidu.com/api?v=2.0&ak= E06EB9D756D0EAFC722EFFB355657B4C "></script>
  10. <title> Vehicle running trajectory Test </title>
  11. <script src="http://c.cnzz.com/core.php"></script></Head >
  12. <body>
  13. <div id="Allmap"></div>
  14. </body>
  15. </html>
  16. <script type="Text/javascript">
  17. var startlong = 106.652024;
  18. var startlat = 26.617221;
  19. var endlong = 106.652024;
  20. var endlat = 26.614221;
  21. var startlongr = 106.652024;
  22. var startlatr = 26.617221;
  23. var endlongr = 106.652024;
  24. var endlatr = 26.614221;
  25. var linespoints = null;
  26. Baidu Map API Features
  27. var map = new Bmap.map ("Allmap"); Create a map instance
  28. Map.centerandzoom (New Bmap.point (106.652024,26.617221), 15); Initialize map, set center point coordinates and map level
  29. Map.addcontrol (New Bmap.maptypecontrol ()); Add a Map type control
  30. Map.setcurrentcity ("Guiyang"); Set the city that the map displays this item is required to be set
  31. Map.enablescrollwheelzoom (TRUE); Turn On mouse wheel zoom
  32. SetInterval (goway,500);
  33. var carmk;
  34. var myicon = new Bmap.icon ("Http://sandbox.runjs.cn/uploads/rs/101/wmbvrxnx/kache.png", New Bmap.size (37,25) , {imageoffset:new bmap.size (0, 0)});//Truck
  35. function Goway () {
  36. Startlong = Endlong;
  37. Startlat = Endlat;
  38. Endlong = getround (endlong);
  39. Endlat = getround (Endlat);
  40. DrawIcon (Startlong,startlat,endlong,endlat);
  41. Drawredline ();
  42. }
  43. function Getround (temp) {
  44. var i = Math.Round (math.random () *9+1);
  45. if (i%2==0) {
  46. return temp + i*0.0001;
  47. }else{
  48. return temp-i*0.0001;
  49. }
  50. }
  51. function GetRound1 (temp) {
  52. var i = Math.Round (math.random () *9+1);
  53. if (i%2==0) {
  54. return temp + i*0.0002;
  55. }else{
  56. return temp-i*0.0002;
  57. }
  58. }
  59. function Drawgreenline (Startlong,startlat,endlong,endlat) {
  60. var polyline = new Bmap.polyline ([
  61. New Bmap.point (Startlong,startlat),//latitude and longitude of starting point
  62. New Bmap.point (Endlong,endlat)//latitude and longitude of terminating point
  63. ], {strokecolor: "green",//Set color
  64. Strokeweight:3,//width
  65. Strokeopacity:1});//Transparency
  66. Map.addoverlay (polyline);
  67. }
  68. function Drawredline () {
  69. Startlongr = Endlongr;
  70. Startlatr = Endlatr;
  71. Endlongr = getRound1 (ENDLONGR);
  72. Endlatr = getRound1 (ENDLATR);
  73. var polyline1 = new Bmap.polyline ([
  74. New Bmap.point (STARTLONGR,STARTLATR),//latitude and longitude of starting point
  75. New Bmap.point (ENDLONGR,ENDLATR)//latitude and longitude of terminating point
  76. ], {strokecolor: "red",//Set color
  77. Strokeweight:3,//width
  78. Strokeopacity:1});//Transparency
  79. Map.addoverlay (POLYLINE1);
  80. }
  81. function DrawIcon (Startlong,startlat,endlong,endlat) {
  82. if (CARMK) {
  83. Map.removeoverlay (CARMK);
  84. }
  85. CARMK = new Bmap.marker (
  86. New Bmap.point (Endlong,endlat),//latitude and longitude of starting point
  87. {Icon:myicon});
  88. Map.addoverlay (CARMK);
  89. Drawgreenline (Startlong,startlat,endlong,endlat);
  90. }
  91. </Script>

Baidu Map API, according to latitude and longitude to achieve vehicle movement trajectory mapping

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.