Skip to content

Instantly share code, notes, and snippets.

@ebinnion
Last active August 29, 2015 14:01
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 ebinnion/7ff42563ca63bb9bb6df to your computer and use it in GitHub Desktop.
Save ebinnion/7ff42563ca63bb9bb6df to your computer and use it in GitHub Desktop.
<?php
$listings = array(
array(
'address' => '3410 Taft Blvd',
'city' => 'Wichita Falls',
'state' => 'Tx',
'zip' => 76308
)
);
foreach ( $listings as $listing ) {
$address = urlencode( "{$listings['address_1']} {$listings['city']} {$listings['state']} {$listings['zip']}" );
$response = json_decode( wp_remote_retrieve_body( wp_remote_get("http://maps.googleapis.com/maps/api/geocode/json?address={$address}&sensor=false") ), true );
$geometry = $response['results'][0]['geometry'];
if( 'OK' == $response['status'] ) {
?>
<iframe width="100%" height="300" style="border: 0;" src="https://www.google.com/maps/?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=<?php echo $address; ?>&amp;t=m&amp;ll=<?php echo $geometry['location']['lat'];?>, <?php echo $geometry['location']['lng'];?>&amp;z=18&amp;iwloc=&amp;output=embed" frameborder="0"></iframe>
<a class="map" title="Get Directions" href="http://maps.google.com/maps?saddr=&amp;daddr=<?php echo $address; ?>" target="_blank">
<small>Click for Directions</small>
</a>
<?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment