简码未在Wordpress中显示地图?

时间:2019-05-28 13:13:29

标签: javascript wordpress google-maps

我写了一个JavaScript代码,该代码在浏览器上似乎可以正常工作,但是当我尝试在wordpress中查看它时,却没有地图。我已经使用WPCoder将代码添加到了wordpress中,然后将该短代码添加到了将显示地图的页面中。

<!DOCTYPE html>
<html>
  <head>
    <title>Place Searches</title>
    <meta name="viewport" content="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>

    <script>
        var map;
    var service;
    var infowindow;

    function initMap() {
      var pyrmont = new google.maps.LatLng(-33.8665433,151.1956316);

      map = new google.maps.Map(document.getElementById('map'), {
          center: pyrmont,
          zoom: 15
        });

      var request = {
        location: pyrmont,
        radius: '5000',
        query: 'Mutli cuisine restaurant',
        center: pyrmont,
      };

      service = new google.maps.places.PlacesService(map);
      service.textSearch(request, callback);
    }

    function callback(results, status) {
      if (status == google.maps.places.PlacesServiceStatus.OK) {
        for (var i = 0; i < results.length; i++) {
          var place = results[i];
          createMarker(results[i]);
        }
      }
    }
    function createMarker(place) {
        var marker = new google.maps.Marker({
          map: map,
          position: place.geometry.location
        });

        google.maps.event.addListener(marker, 'click', function() {
          infowindow.setContent(place.name);
          infowindow.open(map, this);
        });
      }
    </script>

  </head>
  <body>
    <div id="map"></div>
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBqKuEuFOEKe7ErGlm1q3K-dXPXYOI0sc8&libraries=places&callback=initMap" async defer></script>
  </body>
</html>

这在浏览器中工作正常,但wordpress页面根本不显示地图。只是一个纯白的屏幕。

0 个答案:

没有答案