dongyue0225 2017-03-03 07:39
浏览 69

wordpress与谷歌地图API不起作用

i am using PHP and MYSQL on WordPress with Google Map API where i am retrieving data from the MYSQL database and display markers on the Google Map based on the coordinates retrieved from the database.

the problem is that noting is displayed in the web page, can anyone tell me where is the error in my 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">
     <style>
      /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
      #map {
        height: 100%;
      }
      /* Optional: Makes the sample page fill the window. */
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
    </style>

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

     var map;
      function initMap() {
        map = new google.maps.Map(document.getElementById('map'), {
          zoom: 16,
          center: new google.maps.LatLng(-33.91722, 151.23064),
          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
            global $wpdb;
              $prependStr ="";
              foreach( $wpdb->get_results("SELECT * FROM site_coordinates2") as $key => $row) 
              {
                  $latitude = $row->latitude;
                  $longitude = $row->longitude;
                  $info = $row->siteID;
             echo $prependStr;
           ?>
    {

    position: new google.maps.LatLng(<?php echo $latitude ?>, <?php echo $latitude ?>),
    type: '<?php echo $info;?>'
   }
   <?php
   $prependStr =",";
   }


  ?>
}
    </script>

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

<?php
get_footer();
?>
  • 写回答

1条回答 默认 最新

  • dsfdsf23423 2017-03-03 07:48
    关注

    I think the problem from setting the height. See Here

    But in my cases, set the specific pixel to map div. Like this #map {min-height: 600px;}

    评论

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?