user1143896
user1143896

Reputation: 97

PHP Google maps embedding with dynamic locations

Hey there im trying to use google maps iframe to show a map with the direction between 2 locations in my site. The problem with this is that i constantly need to reload the page with different addresses and i am unable to simply replace the iframe's cities in order to bring up new results.

Heres the code for the iframe

<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.uk/maps?f=d&amp;source=s_d&amp;saddr=london&amp;daddr=Leeds,+UK&amp;hl=en&amp;geocode=FaHzEQMd-wv-_yl13iGvC6DYRzGZKtXdWjqWUg%3BFT_xNAMd6V7o_ymZvWTaSj55SDGp3BMC_bqtUQ&amp;aq=1&amp;oq=l&amp;sll=53.800651,-4.064941&amp;sspn=22.225372,67.631836&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;ll=52.654755,-0.848175&amp;spn=2.29307,1.44201&amp;output=embed"></iframe><br /><small>

What i was trying to do is simply replace the city names through php(e.g. london with <?php $firstTown ?>) but no luck in updating the result as it appears to be using the old coordinates.

How would i go on about viewing a map with php variable cities on every page load?

Thanks for your help

Upvotes: 0

Views: 6900

Answers (1)

Jonathan Joosten
Jonathan Joosten

Reputation: 1509

<? 
if ($partner->post_adres)
{
$map_url = $partner->post_adres.','.$partner->post_postcode.','.$partner->post_city;
$map_url = str_replace(" ", "+", $map_url);
?>
<iframe width="350" height="250" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"  src="http://maps.google.nl/maps?q=<?=$map_url?>&hl=nl&ie=UTF8&t=v&hnear=<?=$map_url?>&z=13&amp;output=embed"></iframe>
<?php
}

Works for me

Upvotes: 2

Related Questions