php 使用Shortcode和API密钥将Google Map嵌入到页面中

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 使用Shortcode和API密钥将Google Map嵌入到页面中相关的知识,希望对你有一定的参考价值。

<?php

function google_maps() {
	if ( is_page(9) ) {
		$api_key = 'AIzaSyBRzYU6djisz4_Tmy4VZs6ozGfYzPwTGZY';
	echo'<script src="https://maps.googleapis.com/maps/api/js?key=' . $api_key .'"></script>';
	echo'<script>
            function initialize() {
				var myLatlng = new google.maps.LatLng(33.828811, -84.499637);
				var mapOptions = {zoom: 11, center: myLatlng, scrollwheel: false}
				var map = new google.maps. Map(document.getElementById("googleMap"), mapOptions);

				var marker = new google.maps.Marker ({
					position: myLatlng,
					title: "Safety Net Recovery"
				});
				
				// To add the marker to the map, call setMap();
				marker.setMap(map);
            }
            google.maps.event.addDomListener(window, "load", initialize);
        </script> ';
	}	
}

add_action('wp_footer', 'google_maps');

以上是关于php 使用Shortcode和API密钥将Google Map嵌入到页面中的主要内容,如果未能解决你的问题,请参考以下文章