구글 지도에 궤적을 그리다

3181 단어
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title> </title>
  <script src="Scripts/jquery-1.8.3.min.js"></script>
  <script type="text/javascript" src="http://ditu.google.cn/maps/api/js?sensor=true&language=cn&libraries=weather,places "></script>
  <script type="text/javascript">   
    $(function(){
      // 
      var map = "";
      // 
      var lists = [{ lon:112.856175924414, lat:22.2118355116 }, { lon:112.856010115522, lat:22.211950698 }, { lon:112.856112997028, lat:22.211877583 }, { lon:112.856374689576, lat:22.2118142414 }, { lon:112.857356497151, lat:22.212385636 }, { lon:112.857619172159, lat:22.2126681546 }, { lon:112.858025644973, lat:22.2136272008 }, { lon:112.85837321685, lat:22.213975574 }, { lon:112.858243377764, lat:22.2138238168 }, { lon:112.858105547247, lat:22.2136920628 }, { lon:112.856534535205, lat:22.2110873082 }, { lon:112.855521787459, lat:22.210086129 }, { lon:112.85497642939, lat:22.2102098442 }];

      // 
      var latlng = new google.maps.LatLng(lists[0].lat, lists[0].lon);
      var mapOptions = {

        center: latlng,

        zoom: 16,

        mapTypeId: google.maps.MapTypeId.ROADMAP

      };
      map = new google.maps.Map(document.getElementById("box_map"), mapOptions);

      // 
      new google.maps.Marker({ position: latlng, map: map, icon: "../images/icon_marka.png" });

      // 
      //var latlngArr = [new google.maps.LatLng(22.2118355116, 112.856175924414), new google.maps.LatLng(22.211950698, 112.856010115522)...]
      // 
      var latlngArr = []
      for (var i = 0; i < lists.length; i++) {
        latlngArr[i] = new google.maps.LatLng(lists[i].lat, lists[i].lon);
      }
      // 
      var flightPath = new google.maps.Polyline({
        path: latlngArr,
        strokeColor: "#FF0000",
        strokeOpacity: 1.0,
        strokeWeight: 3
      });
    flightPath.setMap(map);

    // 
    var index = 0, marker = "";
    timer = window.setInterval(function () {
      // 
      //map.panTo(latlngArr[index])
      if (!marker) {
        marker = new google.maps.Marker({ position: latlngArr[index++], map: map });

      }else {

          if (index < latlngArr.length) {
            marker.setPosition(latlngArr[index++]);
          } else {
            index = 0;
            window.clearInterval(timer);
          }
        }
      }, 300);
    })

  </script>

</head>

<body>
  <div id="box_map" style="width: 1000px; height: 800px"></div>
</body>

</html>

좋은 웹페이지 즐겨찾기