Skip to content

Instantly share code, notes, and snippets.

@ylkyrg
Created June 25, 2018 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ylkyrg/115f70aa5c7961a9554f6f0e4854a2f9 to your computer and use it in GitHub Desktop.
Save ylkyrg/115f70aa5c7961a9554f6f0e4854a2f9 to your computer and use it in GitHub Desktop.
<?php
/* Google Map WP Shortcode */
function googleMap( $atts, $content = null ) {
extract( shortcode_atts(
[
"id" => 'cpmap',
"type" => 'road',
"latitude" => '36.742541',
"longitude" => '-5.166578',
"zoom" => '15',
"width" => '100%',
"height" => '500'
],
$atts
));
$mapType = '';
if ( $type == "satellite" ) $mapType = "SATELLITE";
else if ( $type == "terrain" ) $mapType = "TERRAIN";
else if ( $type == "hybrid" ) $mapType = "HYBRID";
else $mapType = "ROADMAP";
echo
'<script type="text/javascript">
(function() {
function initMap() {
var myLatlng = new google.maps.LatLng(' . $latitude . ',' . $longitude . ');
var myOptions = {
center: myLatlng,
scrollwheel: false,
zoom: ' . $zoom . ',
mapTypeId: google.maps.MapTypeId.' . $mapType . '
};
var map = new google.maps.Map(document.getElementById("' . $id . '"), myOptions);
}
initMap();
})();
</script>';
return '<div id="'.$id.'" style="width:'.$width.'px; height:'.$height.'px;" class="googleMap"></div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment