PHP Google maps embedding with dynamic locations - php

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&source=s_d&saddr=london&daddr=Leeds,+UK&hl=en&geocode=FaHzEQMd-wv-_yl13iGvC6DYRzGZKtXdWjqWUg%3BFT_xNAMd6V7o_ymZvWTaSj55SDGp3BMC_bqtUQ&aq=1&oq=l&sll=53.800651,-4.064941&sspn=22.225372,67.631836&mra=ls&ie=UTF8&t=m&ll=52.654755,-0.848175&spn=2.29307,1.44201&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

<?
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&output=embed"></iframe>
<?php
}
Works for me

Related

can not save the whole code of soundcloud embed code to the database

I'm trying to insert the coundcloud embed code to the database to play audio files from soundcloud on a webpage. the embed code is like this
<iframe width="100%" height="166" scrolling="no" frameborder="no"
src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks
/00112233&color=ff5500&auto_play=false&hide_related=false&
show_comments=true&show_user=true&show_reposts=false"></iframe>
using this php code
$code=htmlspecialchars($_REQUEST['code'],ENT_QUOTES);
echo $code;
$stmt = $db->prepare("insert into audio (Code) values (:code)");
$stmt->bindParam(':code',$code);
$stmt->execute();
But it does not save the whole code the echo line prints this "which is saved to the database"
<iframe width="100%" height="166" scrolling="no" frameborder="no"
src="https://w.soundcloud.com/player/?url=https://api.soundcloud.com/tracks/00112233
and does not get this part of the code
&color=ff5500&auto_play=false&hide_related=false&
show_comments=true&show_user=true&show_reposts=false"></iframe>
so how to change the php code to get the whole embed code?

Loading iframe (google map) stored in variable loaded from mysql into a div from link

I have been trying ot hunt this down all afternoon, Im pretty new to all this and am building my first site with php
what Im trying to do is I have a google maps embed code stored in a Db which I have assigned to a variable $map, I want to inject the embed code into an existing div.
So basically a click here for map. I may be way off on what I can do here.
Im sure there is a fancier way to do this but Im just learning and trying something simple.
Sorry if this is something that is obvious.
I have no code to show as i have murdered it and it is an unhelpful mess now.
If the page has already been served to the user, you'll need to use javascript to update the div, or reload the page. I jQuery's .post method to dynamically refresh divs with using AJAX. Info at http://api.jquery.com/jQuery.post/.
I use the following code on my website, which sounds similar to what you're trying to do, but in my case, I'm passing the address to the embed code in the $addresssubjectfullgoogle variable:
<iframe width="100%"
height="350"
frameborder="1"
scrolling="no"
marginheight="0"
marginwidth="0" src="
https://maps.google.com/?f=q&t=h&ie=UTF8&output=embed&q=<?php echo $addresssubjectfullgoogle;?>&z=18&ll=<?php echo $addresssubjectfullgoogle;?>&ie=UTF8">
</iframe>
I suspect that you could do something similar except that in your case, the same could might look something like this:
<iframe width="100%"
height="350"
frameborder="1"
scrolling="no"
marginheight="0"
marginwidth="0" src="<?php echo $map;?>">
</iframe>
I hope that's helpful.

PHP: Using google map embed iframe and pulling a postcode from the database to display

http://www.youtube.com/watch?v=HTm-3Cduafw
Above is basically what I am after but I have tried everything to get it working...I want to pull the postcode from the database and use that, instead of a full address. Its so each user has a different map position, based on what postcode is stored in their account, in the database.
Im using dreamweaver, I have brought in the recordset and the php bit that I am trying to use is below.
<?php echo "$postcode";?>
Above is the snippet and below is what i have so far
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=<?php echo "$postcode";?>&aq=&t=h&g=<?php echo "$postcode";?>&ie=UTF8&hq=&hnear=<?php echo "$postcode";?>&z=13&output=embed"></iframe>
Thanks guys!
Just use & instead of &, because $amp; is the html tag

How to get around This Content cannot be displayed in a frame? (Youtube issue)

I'm trying to keep a database of posted videos on a site I am currently developing. To be able to do this I have to store the URLs of the videos into a database and then I call the url from the database using php and sql by doing this bare in mind I am using this from a php defined area on my homepage. If I use this code it works on other video post sites!
echo '<iframe width="640" height="390" src="', $row['Post_URL'],'"frameborder="0" allowFullScreen></iframe>';
This will not work it says content cannot be displayed in a frame but if I do this it works.
<?php
echo '<iframe width="560" height="315" src="http://www.youtube.com/embed/wardQ7W8hPU" frameborder="0" allowfullscreen></iframe>';
?>
why does the one work properly and the other not? what is a way around this so I can call from the database into php and echo it out so it will display properly on the page?
I got the same problem today. As stated in one of the comments, the problem is the url used...
The iframe embed only works with urls looking like:
http://www.youtube.com/embed/[video_id]
Most of people are using the "share" feature, that generates minified urls like:
http://youtu.be/[video_id]
However, if you look into the "embed" feature, you'll notice that it generates an iframe with src urls like the first example.
So to answer the question, when using iframes to embed, use the src url like the first example.
Try this
<iframe width="640" height="390" src="<?php echo $row['Post_URL'] ?>" frameborder="0" allowFullScreen></iframe>
OR this
<?php
echo "<iframe width='640' height='390' src='{$row['Post_URL']}' frameborder='0' allowFullScreen></iframe>";
?>
OR this
<?php
echo "<iframe width='640' height='390' src='" . $row['Post_URL'] . "' frameborder='0' allowFullScreen></iframe>";
?>
they all are the same and will do the same process.
I'm doing this with dynamic data and it's easier for the client to use the youtube Share link.
So... it's then just a matter of getting the youtube video ID from that url.
// we can't use the "share" link so need to just get the video ID
$youtubePath = parse_url($youtubeShareLink,PHP_URL_PATH);
$youtubeId = str_replace('/','',$youtubePath);
and now we can use the ID in an iframe (adjust width and height per embed options in youtube)
<iframe width="560" height="315" src="//www.youtube.com/embed/<? echo $youtubeId; ?>?rel=0" frameborder="0" allowfullscreen></iframe>

PHP Form to MySQL Embed

I have a form for updating my database. The form contains an embed-video-section which calls the embed code on a separate page to display the video in the page.
The problem is that embed links uses <iframes> which would be removed by my striptags.
I need some help in safely inserting the embed code from my form to my database.
The embed codes look like this
<iframe width="420" height="315" src="http://www.youtube.com/embed/Ahg6qcgoay4" frameborder="0" allowfullscreen></iframe>
or <iframe src="http://blip.tv/play/hIVVgfKwRgI.html" width="550" height="339" frameborder="0" allowfullscreen></iframe>
You could try to use BBCodes. For example, [embed param1=value param2=value] and so on..

Categories