Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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
You can’t perform that action at this time.