html - 不明白为什么我的映射点不显示

标签 html image google-maps marker points

我正尝试在我的 google maps api 上使用叠加层来显示一组 parking 图标,但由于某种原因无法让它工作。

我为我的 html 创建了一个 js fiddle here .这是它的开头:

  function setMarkers(map, locations) {

      var image = new google.maps.MarkerImage('parkingIcon.png');
  };

感谢任何帮助。谢谢。

最佳答案

好的,试试这个代码:

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      html {
        height: 100%
      }
      body {
        height: 100%;
        margin: 0;
        padding: 0
      }
      #map_canvas {
        height: 100%
      }
    </style>
    <script type="text/javascript"
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAoiYR3lgzcF8CxuOwe7SYsJAPjZQXOhQQ&sensor=false"></script>
    <script type="text/javascript">
      var line;
      var map;
      var loc;
      var locations = [];
      var image = new google.maps.MarkerImage('parkingIcon.png');

      function initialize() {
        var raleigh = new google.maps.LatLng(35.77425, -78.639248);
        var mapOptions = {
          zoom : 17,
          minZoom : 17,
          center : raleigh,
          mapTypeId : google.maps.MapTypeId.HYBRID
        }
        map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
        var cityPlaza;

        /*var RLINELayer = new google.maps.KmlLayer('http://caseymmiller.com/j586/MapsTest/RLINE.kml');
         RLINELayer.setMap(map);*/

        var plazaCoords = [
          new google.maps.LatLng(35.773893, -78.63854),
          new google.maps.LatLng(35.772944, -78.638594),
          new google.maps.LatLng(35.772962, -78.639345),
          new google.maps.LatLng(35.773884, -78.63928)
        ];

        cityPlaza = new google.maps.Polygon({
          paths : plazaCoords,
          strokeColor : "#33CCFF",
          strokeOpacity : 0.8,
          strokeWeight : 2,
          fillColor : "#33CCFF",
          fillOpacity : 0.35
        });
        cityPlaza.setMap(map);

        var parking = [
          ['Salisbury Deck', 35.775007, -78.640804],
          ['Cabarrus Deck', 35.774589, -78.640793],
          ['Hannover Deck', 35.774511, -78.640031],
          ['Convention Center Underground Deck', 35.773292, -78.639355],
          ['Performing Arts Deck', 35.772666, -78.641576],
          ['Charter Square Deck', 35.773893, -78.638551],
          ['Blount Street Deck', 35.776226, -78.637499],
          ['McDowell Street Surface Parking', 35.775303, -78.641673],
          ['Salisbury Parking Lot', 35.775442, -78.640814],
          ['Convention Center Parking Lot', 35.772553, -78.639527],
          ['Lenoir Street Parking Lot', 35.773231, -78.638207],
          ['Carrabus street Parking Lot', 35.774032, -78.63824]
        ];

        for (var i = 0; i < parking.length; i++) {
          createMarker(parking[i]);
        }

        var lineCoordinates = [new google.maps.LatLng(35.779742, -78.643389), new google.maps.LatLng(35.77438, -78.643733), new google.maps.LatLng(35.774259, -78.640396), new google.maps.LatLng(35.772953, -78.640482), new google.maps.LatLng(35.772866, -78.638465), new google.maps.LatLng(35.776879, -78.638315), new google.maps.LatLng(35.776766, -78.634989), new google.maps.LatLng(35.778097, -78.634883), new google.maps.LatLng(35.778202, -78.638209), new google.maps.LatLng(35.781178, -78.638059)];

        var lineSymbol = {
          path : google.maps.SymbolPath.CIRCLE,
          scale : 8,
          strokeColor : '#000'
        };

        line = new google.maps.Polyline({
          path : lineCoordinates,
          strokeColor : '#C82536',
          icons : [{
            icon : lineSymbol,
            offset : '100%'
          }],
          map : map
        });
        animateCircle();
      }

      function animateCircle() {
        var count = 0;
        var time = offsetId = window.setInterval(function() {
          count = (count + 1) % 2400;

          var icons = line.get('icons');
          icons[0].offset = (count / 24) + '%';
          line.set('icons', icons);
        }, 20);
      }

      function createMarker(parking) {
        var myLatLng = new google.maps.LatLng(parking[1], parking[2]);
        console.log(myLatLng.toUrlValue());
        var marker = new google.maps.Marker({
          position : myLatLng,
          map : map,
          //icon : image   //<---- Get rid the comment after upload "parkingIcon.png" file.
          /*title: parking[0],*/
        });
        return marker;
      }

    </script>
  </head>
  <body onload="initialize()">
    <div id="map_canvas" style="width:100%; height:100%"></div>
  </body>
</html>​

关于html - 不明白为什么我的映射点不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13575419/

相关文章:

javascript - 如何评估 ng-Class 指令中的作用域对象?

javascript - CSS,链接无效

javascript - 如何在javascript中叠加图像?

html - 缩小时过大的图像模糊

javascript - 如何让 'button' 在 MouseDown 上创建一个可移动的 DIV,并将 'MouseDown' 切换到新的 DIV?

Javascript AJAX 无法在 ASP.NET C# 上运行并返回 404

android - 如何将图像传递到 Android 中的 ArrayList<String>?

google-maps - 在谷歌地图上显示多条路线

c# - 使用 Json.Net 解析 Google Maps Geocode API

javascript - 谷歌地图通过 Backbone javascript在div标签中返回但不显示