juandahveed
9/28/2017 - 1:15 PM

Embed Google Map onto Page with Shortcode and API key

Embed Google Map onto Page with Shortcode and API key

<?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');