dongyuan8469 2017-03-06 07:34
浏览 115
已采纳

标记不会显示在Google地图API上

i am using PHP & MYSQL on wordpress in order to retrieve data from the database that contains coordinates and display markers on the Google Map.

Google Map is shown but without any markers and i did not found the error in my PHP code.

code

     <?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();
    ?>
  • 写回答

2条回答 默认 最新

  • douhuiqi3855 2017-03-06 13:43
    关注

    There may be no error becouse it doesnt find the icon. icon: icons[feature.type].icon, so try to look into that.

    happy i could help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私