Google地图无法在我的Wordpress网站上运行

时间:2017-10-09 12:00:11

标签: javascript wordpress google-maps google-maps-markers

function initMap() {
        var myLatLng = {lat: 42.864281, lng: -85.761323};

        var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 15,
          center: myLatLng,
		  styles: [
			  {
				"elementType": "geometry",
				"stylers": [
				  {
					"color": "#f5f5f5"
				  }
				]
			  },
			  {
				"elementType": "labels.icon",
				"stylers": [
				  {
					"visibility": "off"
				  }
				]
			  },
			  {
				"elementType": "labels.text.fill",
				"stylers": [
				  {
					"color": "#616161"
				  }
				]
			  },
			  {
				"elementType": "labels.text.stroke",
				"stylers": [
				  {
					"color": "#f5f5f5"
				  }
				]
			  },
			  {
				"featureType": "administrative.land_parcel",
				"elementType": "labels.text.fill",
				"stylers": [
				  {
					"color": "#bdbdbd"
				  }
				]
			  },
			  {
				"featureType": "poi",
				"elementType": "geometry",
				"stylers": [
				  {
					"color": "#eeeeee"
				  }
				]
			  },
			  {
				"featureType": "poi",
				"elementType": "labels.text.fill",
				"stylers": [
				  {
					"color": "#757575"
				  }
				]
			  },
			  {
				"featureType": "poi.park",
				"elementType": "geometry",
				"stylers": [
				  {
					"color": "#e5e5e5"
				  }
				]
			  },
			  {
				"featureType": "poi.park",
				"elementType": "labels.text.fill",
				"stylers": [
				  {
					"color": "#9e9e9e"
				  }
				]
			  },
			  {
				"featureType": "road",
				"elementType": "geometry",
				"stylers": [
				  {
					"color": "#ffffff"
				  }
				]
			  },
			  {
				"featureType": "road.arterial",
				"elementType": "labels.text.fill",
				"stylers": [
				  {
					"color": "#757575"
				  }
				]
			  },
			  {
				"featureType": "road.highway",
				"elementType": "geometry",
				"stylers": [
				  {
					"color": "#dadada"
				  }
				]
			  },
			  {
				"featureType": "road.highway",
				"elementType": "labels.text.fill",
				"stylers": [
				  {
					"color": "#616161"
				  }
				]
			  },
			  {
				"featureType": "transit.line",
				"elementType": "geometry",
				"stylers": [
				  {
					"color": "#e5e5e5"
				  }
				]
			  },
			  {
				"featureType": "transit.station",
				"elementType": "geometry",
				"stylers": [
				  {
					"color": "#eeeeee"
				  }
				]
			  },
			  {
				"featureType": "water",
				"elementType": "geometry",
				"stylers": [
				  {
					"color": "#c9c9c9"
				  }
				]
			  },
			  {
				"featureType": "water",
				"elementType": "labels.text.fill",
				"stylers": [
				  {
					"color": "#9e9e9e"
				  }
				]
			  }
			]
		  
        });
		
		
		 var iconBase = 'http://novochirowellness.com/wp-content/uploads/2017/10';
        var icons = {
          parking: {
            icon: iconBase + '/marker.png'
          }
        };
		
		
		var features = [
          {
            position: new google.maps.LatLng(42.864967, -85.757060),
            type: 'parking'
          }
        ];
		
		
		features.forEach(function(feature) {
          var marker = new google.maps.Marker({
		  
            position: feature.position,
            icon: icons[feature.type].icon,
            map: map,
			title: 'Hello World!'
          });
        });
		
		
      }
 #map {
        height: 450px;
        width:100%;
      }
 <script async defer
    src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCmAJDksqECqEpbi3KNKMPkbmVBUeBqu90&callback=initMap">
</script>
<div id="map"></div>

我在wordpress网站内使用谷歌地图。我创建了一个带有标记的自定义谷歌地图。它在第一次之后根本不加载。如果我更新api密钥,那么它只运行一次,在我刷新页面后它不再显示。

控制台没有显示任何错误,我无法找到问题。请帮忙

0 个答案:

没有答案