javascript - 简码未在 wordpress 中显示地图?
问题描述
我编写了一个似乎在浏览器上运行良好的 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 页面根本不显示地图。只是一个纯白的屏幕,没有别的。
解决方案
推荐阅读
- airflow - 有没有办法将气流中的两个任务联系在一起 w/r/t 重试?
- bash - 如何在 sed 命令中包含 1 个或多个空格
- spring-boot - 如何找出是否在 Maven 应用程序中使用了依赖项中的任何类?
- java - 无法使用 jsoup 获取准确的图像和文本
- vb.net - 以适当间距连接可变长度字符串
- postgresql - 如何在同一个 postgres 运算符集群上创建多个数据库?
- java - 数组中的 Java 随机数
- sql - 如何在sql中搜索列表中的字符串?
- django - 序列化多个对象时删除特定实例(many=True),其中一个有错误
- .net - React + SignalR 服务类的最佳方式是什么?