Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript initMap不是函数4_Javascript_Php - Fatal编程技术网

Javascript initMap不是函数4

Javascript initMap不是函数4,javascript,php,Javascript,Php,当我试图在我的网站上显示一个组织的所有公司的地图时,我遇到了一个问题 当我访问我的网站时,我看到地图没有显示。 我将检查项目,并得到错误“initMap不是一个函数” 我不知道为什么会出现这个错误。 你能帮我吗 我附上代码: 函数initMap(){ var map_cnt={lat:41.563211,lng:2.008875}; var map=new google.maps.map(document.getElementById('map'){ 缩放:6, 中心:地图, 滚轮:错误 }

当我试图在我的网站上显示一个组织的所有公司的地图时,我遇到了一个问题

当我访问我的网站时,我看到地图没有显示。 我将检查项目,并得到错误“initMap不是一个函数”

我不知道为什么会出现这个错误。 你能帮我吗

我附上代码:


函数initMap(){
var map_cnt={lat:41.563211,lng:2.008875};
var map=new google.maps.map(document.getElementById('map'){
缩放:6,
中心:地图,
滚轮:错误
});
var mapboond=new google.maps.LatLngBounds();
var mapInfoWindow=new google.maps.InfoWindow();
var marker=new google.maps.marker({
位置:新google.maps.LatLng(,),
地图:地图,
标题:“”
});
extend(marker.getPosition());
google.maps.event.addListener(标记“单击”,函数(){
var tmp=jQuery(“#divEmpresa”);
tmp.弹出窗口(“显示”);
});
map.fitbunds(mapbund);
}
更新代码

<?php
if($_SERVER['REMOTE_ADDR']=='80.32.126.235'){
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
}
$json = file_get_contents('https://aplicatiuspin.cat/aplicatiu/webServices/views/?v=empreses/json&idAplicatiu=59&idEtiqueta=1&template=none');

$empreses = json_decode($json, true);


?>
<div id="map" style="height: 500px; width: 100%;"></div>
<script type="text/javascript">
    function initMap() {
        var map_cnt = {lat:41.563211, lng:2.008875};
        var map = new google.maps.Map(document.getElementById('map'), {
            zoom: 6,
            center: map_cnt,
            scrollwheel: false
        });
        var mapBound = new google.maps.LatLngBounds();
        var mapInfoWindow = new google.maps.InfoWindow();
        <?php
        foreach ($empreses as $e) {
        if (is_numeric($e['latitud']) && is_numeric($e['longitud'])) {
        ?>
        var marker<? echo $e['id'];?> = new google.maps.Marker({
            position: new google.maps.LatLng(<? echo $e['latitud'];?>, <? echo $e['longitud'];?>),
            map: map,
            title: '<? echo addslashes($e['nom']); ?>'
        });
        mapBound.extend(marker<? echo $e['id'];?>.getPosition());
        google.maps.event.addListener(marker<? echo $e['id'];?>, "click", function () {
            var tmp = jQuery("#divEmpresa<?=$e['id']; ?>");
            tmp.popup('show');
        });

        map.fitBounds(mapBound);
        <?
        }
        }
        ?>
    }
</script>

<script async defer src="https://maps.google.com/maps/api/js?v=3.25&key=enter-your-key-here&callback=initMap"></script>
<script src="https://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="https://cdn.rawgit.com/vast-engineering/jquery-popup-overlay/1.7.13/jquery.popupoverlay.js"></script>


<div style="overflow: hidden; height: 1px; width: 1px;">
<?php
foreach ($empreses as $e):?>
        <div class="divEmpresa" id="divEmpresa<?=$e['id']; ?>" style="background-color: #ffffff; padding: 20px; border-radius: 5px; width: 50%;">
            <div style="text-align: right; padding: 0 5px;">
                <a href="#" class="divEmpresa<?=$e['id']; ?>_close" >
                    <i class="fa fa-times" aria-hidden="true"></i>
                </a>
            </div>
            <div class="row">
                <!--<div class="col-sm-4"><img src="/webServices/views/img/empresa<?=$e['id']; ?>.jpg"> </div>-->
                <div class="col-sm-8"><h2><?=$e['nom']; ?></h2></div>
            </div>
            <div class="row">
                <div class="col-sm-4"></div>
                <div class="col-sm-8">
                    <?=$e['adreca']; ?><br>
                    <?=$e['cp']; ?> - <?=$e['poblacio']; ?> <br>
                    <?=$e['telefon']; ?><br>
                    <a href="<?=$e['web']; ?>" target="_blank"><?=$e['web']; ?></a>
                </div>
            </div>
        </div>
<?
endforeach;
?>
</div>
    <script>
        jQuery( document ).ready(function() {
            jQuery('.divEmpresa').popup({
                transition: 'all 0.3s',
                scrolllock: true
            });
        });
    </script>

函数initMap(){
var map_cnt={lat:41.563211,lng:2.008875};
var map=new google.maps.map(document.getElementById('map'){
缩放:6,
中心:地图,
滚轮:错误
});
var mapboond=new google.maps.LatLngBounds();
var mapInfoWindow=new google.maps.InfoWindow();
var marker=new google.maps.marker({
位置:新google.maps.LatLng(,),
地图:地图,
标题:“”
});
extend(marker.getPosition());
google.maps.event.addListener(标记“单击”,函数(){
var tmp=jQuery(“#divEmpresa”);
tmp.弹出窗口(“显示”);
});
map.fitbunds(mapbund);
}

您必须忘记添加
谷歌api密钥
,如下所示

在这里获取您的数据并添加它

<script async defer
    src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
    </script>


首先,感谢您的回答。我已经替换了代码,所以你提供给我生成的密钥,它一直告诉我相同的。。。代码是这样的:你添加了version-InvalidValueError:initMap不是一个函数吗?首先,我把它放进去,它给了我相同的错误,所以版本中有很多错误需要尝试,但没有解决。你也必须添加callback=initMap。我已将你的代码粘贴到我的机器上,它工作正常。