簡體   English   中英

js Google Map 標記和路徑不出現

[英]Js Google Map Markers and Path Do not appear

我正在嘗試在 map 上實現一個標記,標記將沿着指定路徑移動。 我可以驗證 map 在正確的中心和縮放處正確呈現,但標記和路徑沒有顯示。 任何幫助/建議將不勝感激。 我已經在 firefox 和 chrome 上進行了測試。

我的 html 代碼如下:

<link rel="stylesheet" src="map.css"> </link> 
<script src="https://maps.googleapis.com/maps/api/js?key=mykey&callback=initialize" defer ></script>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
    <script src="map.js"></script>
</head>

<body>
    <div id="app-text"></div>
        <h1 center> Sendy Test </h1> 
        <h3 text-center> Question 1 </h3>
    </div>  

  <div id="map_canvas"></div>
</body>

我的 function 包含在 map.js 文件中,如下所示:

function initialize()
{
    var myOptions = {
        zoom: 16,
        center: new google.maps.LatLng(-1.298982, 36.776811),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    var image = 'https://images.sendyit.com/web_platform/vendor_type/top/2.svg';
    
    marker = new google.maps.Marker({
        position: new google.maps.LatLng(startPos[0], startPos[1]),
        title: "Your driver",
        visible: true,
        map: map,
        icon: image
    });

    marker.setMap(map);
    
    google.maps.event.addListenerOnce(map, 'idle', function()
    {
        animateMarker(marker, [
            // The coordinates of each point you want the marker to go to.
            // You don't need to specify the starting position again.
            [-1.297459, 36.776747],
            [-1.296193, 36.776726],
            [-1.296097, 36.779236],
            [-1.296151, 36.777637],
            [-1.296215, 36.776693],
            [-1.294252, 36.776586],
            [-1.294048, 36.776790],
            [-1.293973, 36.779118],
            [-1.292622, 36.779075],
            [-1.291844, 36.779049],

        ], speed);
    });

    polylineCoords = [];
    
    var startCoords = new google.maps.LatLng(startPos[0], startPos[1]);
    
    polylineCoords.push(startCoords);

    path = new google.maps.Polyline({
      path: polylineCoords,
      geodesic: true,
      strokeColor: '#FF0000',
      strokeOpacity: 1.0,
      strokeWeight: 2
    });
    
    path.setMap(map);
}

initialize();

這個錯誤是因為我在 map 上指定了錯誤的起始 position

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM