Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/378.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 标记不';不显示在谷歌地图API上_Javascript_Php_Mysql_Google Maps - Fatal编程技术网

Javascript 标记不';不显示在谷歌地图API上

Javascript 标记不';不显示在谷歌地图API上,javascript,php,mysql,google-maps,Javascript,Php,Mysql,Google Maps,我在wordpress上使用PHP和MYSQL从包含坐标的数据库中检索数据,并在Google地图上显示标记 谷歌地图显示,但没有任何标记,我没有发现我的PHP代码中的错误 代码 自定义标记 CSS代码 ======== /*始终明确设置贴图高度以定义div的大小 *包含映射的元素*/ #地图{ 高度:600px; } /*可选:使示例页面填充窗口*/ html,正文{ 身高:100%; 保证金:0; 填充:0; } HTML代码与javascript =====================

我在wordpress上使用PHP和MYSQL从包含坐标的数据库中检索数据,并在Google地图上显示标记

谷歌地图显示,但没有任何标记,我没有发现我的PHP代码中的错误

代码

自定义标记
CSS代码
========
/*始终明确设置贴图高度以定义div的大小
*包含映射的元素*/
#地图{
高度:600px;
}
/*可选:使示例页面填充窗口*/
html,正文{
身高:100%;
保证金:0;
填充:0;
}
HTML代码与javascript
=========================
var映射;
函数initMap(){
map=new google.maps.map(document.getElementById('map'){
缩放:8,
中心:新google.maps.LatLng(33.888630,35.495480),
mapTypeId:“路线图”
});
iconBase变量https://maps.google.com/mapfiles/kml/shapes/';
变量图标={
停车场:{
图标:iconBase+“parking\u lot\u maps.png”
},
图书馆:{
图标:iconBase+“library_maps.png”
},
信息:{
图标:iconBase+“info-i_maps.png”
}
};
功能添加标记(功能){
var marker=new google.maps.marker({
位置:feature.position,
图标:图标[feature.type]。图标,
地图:地图
});
}
变量特征=[
PHP代码
========
{
位置:新google.maps.LatLng(,),
类型:“”
}
];
for(变量i=0,特征;特征=特征[i];i++){
添加标记(特征);
}
}

生成位置变量。
var位置=[
[Bondi Beach',-33.890542151.274856,4],
[Coogee Beach',-33.923036151.259052,5],
[Cronulla Beach',-34.028249151.157507,3],
[‘曼利海滩’,-33.80010128657071151.28747820854187,2],
[‘马鲁布拉海滩’,-33.950198151.259302,1]
];
var map=new google.maps.map(document.getElementById('map'){
缩放:10,
中心:新谷歌地图LatLng(-33.92151.25),
mapTypeId:google.maps.mapTypeId.ROADMAP
});
var infowindow=new google.maps.infowindow();
var标记,i;
对于(i=0;i

谷歌地图多个标记

可能没有错误,因为它找不到图标<代码>图标:图标[feature.type].icon,
所以试着查看一下


很高兴我能帮忙。

可能没有错误,因为它找不到图标。`icon:icons[feature.type].icon,`@H.Brendan那么如何修复这个错误呢?我对类型进行了注释并从feature.type中删除,但仍然没有任何功能。我假定标记器不知道位置是什么。试试‘position:new google.maps.LatLng(51.727681,4.9574324)’,‘手动——试着输入坐标,不要从数据库中取出。如果它是硬编码的,那么它就与数据库有关tags@H.Brendan我尝试了你的答案,但它不起作用,我用lat lng替换了该位置的PHP代码,但它没有显示任何错误marker@H.Brendan我需要从数据库中检索数据,而不是我将要打开的这些值还有一个关于信息窗口的问题,因为我试过了,但它不工作。你可以通过点击钩子来关闭这个窗口,你应该这样做。否则,stack会在“你有很多开放性问题”上向mayham提问,我会尝试在信息窗口中提供帮助,所以继续并打开新问题:)
     <?php
            /*
            Template Name: MAP2
            */

            get_header();
      ?>


    <!DOCTYPE html>
    <html>
      <head>
        <title>Custom Markers</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
        <meta charset="utf-8">
        <script async defer
        src="https://maps.googleapis.com/maps/api/js?key=*******&callback=initMap">
        </script>

CSS CODE 
========


    <style>
          /* Always set the map height explicitly to define the size of the div
           * element that contains the map. */
          #map {
            height: 600px;
          }
          /* Optional: Makes the sample page fill the window. */
          html, body {
            height: 100%;
            margin: 0;
            padding: 0;
          }
        </style>

   HTML code & javascript
=========================


 </head>
  <body>
    <div id="map"></div>
    <script>

     var map;
      function initMap() {
        map = new google.maps.Map(document.getElementById('map'), {
          zoom: 8,
          center: new google.maps.LatLng(33.888630, 35.495480),
          mapTypeId: 'roadmap'
        });

        var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/';
        var icons = {
          parking: {
            icon: iconBase + 'parking_lot_maps.png'
          },
          library: {
            icon: iconBase + 'library_maps.png'
          },
          info: {
            icon: iconBase + 'info-i_maps.png'
          }
        };

        function addMarker(feature) {
          var marker = new google.maps.Marker({
            position: feature.position,
            icon: icons[feature.type].icon,
            map: map
          });
        }

        var features = [

PHP code
========


    <?php
              global $wpdb;
                $prependStr ="";
                foreach( $wpdb->get_results("SELECT siteID, latitude, longitude FROM site_coordinates2", OBJECT) as $key => $row) {
                   $latitude = $row->latitude;
                   $longitude = $row->longitude;
                   $info = $row->siteID;
               echo $prependStr;
           ?>
    {
        position: new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>),
        type: '<?php echo $info; ?>'
    }
    <?php
    $prependStr =",";
    }
    ?>
            ];

            for (var i = 0, feature; feature = features[i]; i++) {
              addMarker(feature);
            }
    }

             </script>


      </body>
    </html>

    <?php
    get_footer();
    ?>