简体   繁体   English

无法在Laravel应用程序上加载Google地图

[英]Unable to load google maps on laravel application

I'm trying to load the google maps js API on a Laravel application, and I just keep getting an error 'initMap is not a function'. 我试图在Laravel应用程序上加载google maps js API,但我一直收到错误消息“ initMap不是函数”。

I think it's probably an issue that's related to the visibility of initMap function from the global scope. 我认为这可能与initMap函数在全局范围内的可见性有关。 Error: 错误: 错误

app.blade.php app.blade.php app.blade.php

asset/js/ap/js 资产/ js / ap / js 资产/js/ap.js

it seems obvious but i think you should try loading your 似乎很明显,但我认为您应该尝试加载您的

<script>{{asset(js/app.js)}}</script>

after the googleMap js file 在googleMap js文件之后

(edit) it's likely a async issue, async scripts may be run in any order, regardless of the order in which they appear in the HTML. (edit)这可能是异步问题,异步脚本可以以任何顺序运行,无论它们在HTML中的显示顺序如何。

if you want to keep this behaviour you maybe wrap you init() call in a window.onload callback and remove the &callback=initmap from the google map script 如果您想保持这种行为,则可以将init()调用包装在window.onload回调中,并从Google地图脚本中删除&callback = initmap

window.onload = () => {
    init()
}

another solution is to place the googlemap script before your ap.js and remove the async defer attribute from your ap.js script tag 另一个解决方案是将googlemap脚本放在ap.js之前,并从ap.js脚本标签中删除async defer属性

hope this solve your issue 希望这能解决您的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM