Javascript 第二次调用initmap()product;“谷歌没有定义”;控制台中的错误

Javascript 第二次调用initmap()product;“谷歌没有定义”;控制台中的错误,javascript,php,google-maps,Javascript,Php,Google Maps,在我的应用程序中,我从数据库中获取lat和long,并在谷歌地图上显示标记。 最初,我默认获取lat和long,并加载标记,这很好 现在,在表单提交之后,我从数据库获取输入值和数据,并使用新创建的数组作为参数调用JS函数,并调用initmap() 现在,最疯狂的是我已经实现了我的目标。我的应用程序运行得很好,但在JS控制台中我仍然可以看到未捕获的引用错误:google未定义 我想知道我是否将inimap()称为错误,或者是否有任何建议,我们将不胜感激 这是我的PHP和表单代码- <?PHP

在我的应用程序中,我从数据库中获取lat和long,并在谷歌地图上显示标记。 最初,我默认获取lat和long,并加载标记,这很好

现在,在表单提交之后,我从数据库获取输入值和数据,并使用新创建的数组作为参数调用JS函数,并调用initmap()

现在,最疯狂的是我已经实现了我的目标。我的应用程序运行得很好,但在JS控制台中我仍然可以看到未捕获的引用错误:google未定义

我想知道我是否将inimap()称为错误,或者是否有任何建议,我们将不胜感激

这是我的PHP和表单代码-

<?PHP
    $markingsArray = array();
    //Code to fetch and assign values to array $markingsArray
?>

<form action="" method="get">
    <table style="font:normal 100% 'century gothic', arial, sans-serif">
    <tr>
    <td>Year</td><td>:</td><td><select id="insYear" name="insYear">
    <option>2016</option>
    <option>2017</option>
    <option>2018</option>
    </select> </td>
    </tr>
    <tr>
    <td>Club</td><td>:</td><td><select id="clubname" name="clubname">
      <option>BaseBall</option>
    <option>Football</option>
    <option>Others</option>
    </select> </td>
    <td><input type="submit" name="load" value="Load the club info" class="button button1"></td>
    </tr>
    </table>
</form>

<?PHP
    if(isset($_GET['load'])) {
        $clubInp = $_GET["clubname"];
        $yearInp = $_GET["insYear"];
        $clubyearRequestedData = array();
      //........
      //Here Code to fetch and fill this array $clubyearRequestedData
      //........

      echo "<script async type='text/javascript'>";
      echo"updateFilteredMarkers(".json_encode($clubyearRequestedData).");";
      echo"</script>";
?>

年份:
2016
2017
2018
俱乐部:
棒球
足球
其他
;
函数initMap(){
map=new google.maps.map(document.getElementById('map'){
缩放:14,
中心:新google.maps.LatLng(40.697465,-89.613393),
//disableDefaultUI:true,
mapTypeId:google.maps.mapTypeId.TERRAIN,
fullscreenControl:错误
});
调用this();
其他功能1();
其他功能2();
}
函数updateFilteredMarkers(ClubyArrRequestedData){
markingsLocal=ClubyArrRequestedData;
initMap();
}
函数调用this(){

对于(var i=0;i当您发布表单时,页面将重新加载。在这种情况下,您在加载API之前调用
updateFilteredMarkers
,生成您看到的消息,然后当加载API时,它再次运行
initMap
,这次它工作(因为加载了API)。您不需要在
updateFilteredMarkers
内部调用
initMap
,因为它将在加载API后运行。

Hi,我需要调用initMap()函数中调用的三个不同函数,所以我想我可以直接调用initMap()减少几行代码以保持整洁。我明白你的意思,我尝试了你的建议,但仍然显示出相同的错误。
   <script type='text/javascript'>
    var markingsLocal = <?php echo json_encode($markingsArray); ?>;

    function initMap() {
        map = new google.maps.Map(document.getElementById('map'), {
        zoom: 14,
        center: new google.maps.LatLng(40.697465, -89.613393),
        //disableDefaultUI: true,
        mapTypeId: google.maps.MapTypeId.TERRAIN,
        fullscreenControl: false
    });

    callingThis();
    otherFunction1();
    otherFunction2();
    }

    function updateFilteredMarkers(clubyearRequestedData){
        markingsLocal = clubyearRequestedData;
        initMap();
    }

    function callingThis(){
        for (var i=0;i<markingsLocal.length;i++){
        //Using the array values to create markers on map.
    }
</script>
<script async defer
    src="https://maps.googleapis.com/maps/api/js?key=xxxxxxxxMyAPIKeyxxxxxxxxxx&libraries=places&callback=initMap">
</script>