Created
June 25, 2018 16:07
-
-
Save ylkyrg/115f70aa5c7961a9554f6f0e4854a2f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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