我想要在我的 Laravel 專案中使用谷歌地圖,我可以在地圖中繪制復雜的折線,但地圖根本沒有顯示。它只顯示一個空白 div。
<tr>
<td colspan="4">
<div id="map"></div>
</td>
</tr>
<!-- Map Script -->
<script
src="https://maps.googleapis.com/maps/api/js?key=MYAPIKEY&callback=initMap&v=weekly&channel=2"
async></script>
<script>
// This example creates a 2-pixel-wide red polyline showing the path of
// the first trans-Pacific flight between Oakland, CA, and Brisbane,
// Australia which was made by Charles Kingsford Smith.
function initMap() {
const map = new google.maps.Map(document.getElementById("map"), {
zoom: 3,
center: { lat: 0, lng: -180 },
mapTypeId: "terrain",
});
const flightPlanCoordinates = [
{ lat: 37.772, lng: -122.214 },
{ lat: 21.291, lng: -157.821 },
{ lat: -18.142, lng: 178.431 },
{ lat: -27.467, lng: 153.027 },
];
const flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
geodesic: true,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2,
});
flightPath.setMap(map);
}
</script>
我必須安裝任何特定的軟體包才能運行此組件嗎?或者我需要在任何檔案中定義什么?請幫助我,每當我看到與我相同的問題時,都沒有答案....
uj5u.com熱心網友回復:
當我將 javascript 函式放在 HTML 之前時,地圖會出現功能折線。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/427063.html
標籤:javascript 谷歌地图
下一篇:顫動的谷歌地圖不顯示標記
