Last active
August 29, 2015 14:25
-
-
Save dboutote/1076a09b714e54c8a179 to your computer and use it in GitHub Desktop.
Builds A Link to Google Maps (for WordPress theme)
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 | |
/** | |
* Build a Static Map link to Google Maps | |
* | |
* @since 1.0 | |
* | |
* @param string $lat the requested Latitude of the location. Required, default is empty. | |
* @param string $lng the requested Longitude of the location. Required, default is empty. | |
* @return mixed The url if successful. Empty otherwise. | |
*/ | |
function _get_google_img_map( $args = array() ){ | |
$defaults = array( | |
'latitude' => '', | |
'longitude' => '', | |
'maptype' => 'roadmap', | |
'size' => '216x160', | |
'zoom' => '13', | |
'marker_size' => '', | |
); | |
$args = wp_parse_args($args, $defaults); | |
if( empty($args['latitude']) || empty($args['longitude']) ){ | |
return ''; | |
} | |
$query_args = array( | |
'center' => $args['latitude'] . ',' . $args['longitude'], | |
'zoom' => $args['zoom'], | |
'size' => $args['size'], | |
'maptype' => $args['maptype'], | |
); | |
if('' !== $args['marker_size']) { | |
$query_args['markers'] = 'size:' . $args['marker_size'] . '|' . $args['latitude'] . ',' . $args['longitude']; | |
} | |
$url = add_query_arg( | |
$query_args , | |
'//maps.googleapis.com/maps/api/staticmap' | |
); | |
return $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment