daily menu » rate the banner | guess the city | one on one

Go Back   SkyscraperCity > Fun Forums > About the forums

About the forums » testing | archive


Reply

 
Thread Tools Display Modes
Old October 25th, 2010, 02:14 AM   #1
.for.ce.br
BANNED
 
Join Date: Sep 2010
Location: Fortaleza, Brazil
Posts: 1,144
Likes (Received): 0

Embed Google Maps

Why not have a tag [googlemaps] [/googlemaps] to easily embed the interactive maps from Google Maps?

It should not be so difficult to create something like this...
.for.ce.br no está en línea   Reply With Quote

Sponsored Links
 
Old October 26th, 2010, 01:44 PM   #2
.for.ce.br
BANNED
 
Join Date: Sep 2010
Location: Fortaleza, Brazil
Posts: 1,144
Likes (Received): 0

Here is a simple PHP code that can do the job.

The user inserts the direct link from Google Maps (the direct link, not the link for embedding), between the tags [googlemaps] and [/googlemaps].

The code bellow takes the direct link inserted between the tags, and extract the coordinates and zoom level from it, to use them in the prefabricated code for iframe embedding.


PHP Code:
<?php

/*

Code by .for.ce.br (SkyscraperCity user)

Some code here to get the text between the tags [googlemaps] and [/googlemaps], the same way you can get the text between [youtube] and [/youtube]

Store the text you got in a variable called $intertags
*/


// Get the first 22 characters of the text stored in $intertags:
$check substr($intertags,0,22);


// check if the text is a link from Google Maps:
if ($check == "http://maps.google.com") {


// Findind the coordinates and zoom level:
$position1 =  strpos($intertags"ll=");
$position2 =  strpos($intertags"&spn=");
$position3 =  strpos($intertags"&z=");


$coordinates substr($intertags,$position1+3$position2-$position1-3);
$zoomlevel substr($intertags,$position3+32);

// The zoom level can have one or two characters, the code bellow handles with this issue:
$second substr($zoomlevel,1,1);
$numbers = array("0""1""2""3""4""5""6""7""8""9"); 
if (!
in_array($second$numbers)) { $zoomlevel substr($zoomlevel,0,1); }


// Finally, this is the code of an iframe, pointing to Google Maps, with the coordinates and zoom level you got from the link inserted by the user:

$code "<iframe width='650' height='400' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='http://maps.google.com/maps?hl=en&amp;ie=UTF8&amp;ll=$coordinates&amp;z=$zoomlevel&amp;output=embed'></iframe><br />
<small><a href='http://maps.google.com/maps?hl=en&amp;ie=UTF8&amp;ll=
$coordinates&amp;z=$zoomlevel&amp;source=embed' style='color:#0000FF;text-align:left'> Full view on Google Maps</a></small>" ;

echo 
$code;

}


?>


The code is free, you can use it if you want.

Regards.

Last edited by .for.ce.br; October 26th, 2010 at 03:38 PM.
.for.ce.br no está en línea   Reply With Quote
Old October 26th, 2010, 04:21 PM   #3
invincible
Lurker
 
invincible's Avatar
 
Join Date: Sep 2002
Location: Melbourne
Posts: 3,392
Likes (Received): 13

iframes would be a security risk and the correct way to embed maps is to register for the Google Maps API and use that, but the work required to do something like that would be more complex.

(note: this is my personal opinion and does not represent the viewpoint of site admins)
__________________
Opinions are like arseholes, everyone has one and everyone thinks that theirs is the only one that doesn't stink.

invincible no está en línea   Reply With Quote
Old October 26th, 2010, 06:25 PM   #4
.for.ce.br
BANNED
 
Join Date: Sep 2010
Location: Fortaleza, Brazil
Posts: 1,144
Likes (Received): 0

I think iframes would not be a security risk if the "src" property is rigidly controlled. The PHP script gets the direct link, extracts the coordinates and zoom level from it, and insert them in the "src" property of the iframe. The user will not be allowed to determine what the src will be.

Using the Google Maps API would require in first place register to get an ID with Google. It also can be done, but is a little bit more complicated. In return, the API uses a DIV, not an IFRAME...
.for.ce.br no está en línea   Reply With Quote
Old October 26th, 2010, 06:32 PM   #5
.for.ce.br
BANNED
 
Join Date: Sep 2010
Location: Fortaleza, Brazil
Posts: 1,144
Likes (Received): 0

Anyway, if the Google Maps API is used, the code I posted above can be used to obtain the $coordinates and $zoomlevel from the direct link between the tags, and then the variables are inserted into the API's function "map.setCenter".

PHP Code:

<?php

$setcenter 
"map.setCenter(new GLatLng($coordinates), $zoomlevel, G_NORMAL_MAP);" ;

?>
.for.ce.br no está en línea   Reply With Quote
Old November 30th, 2010, 01:36 AM   #6
.forr.ce.br
BANNED
 
Join Date: Nov 2010
Posts: 1
Likes (Received): 0

I'm here just to clarify that, since I was unfairly banned from Skyscrapercity, I no longer will be offering this PHP code for free to this website. I withdraw the offer of the above PHP code. Skyscrapercity can not use the code created by me any time in the future.

I no longer have any interest about this website packed with arrogant, autoritarian and foolish moderators.

Goodbye.
.forr.ce.br no está en línea   Reply With Quote
Old December 2nd, 2010, 01:14 PM   #7
JoHaN 15
Lebensraum
 
JoHaN 15's Avatar
 
Join Date: Apr 2008
Location: Praetoria | Centvrion
Posts: 8,118
Likes (Received): 336

I'm still gonna use your code though
__________________
The boys, the girls they all like Carmen
She laughs like god, her mind's like a diamond
JoHaN 15 no está en línea   Reply With Quote


Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT +2. The time now is 03:32 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Feedback Buttons provided by Advanced Post Thanks / Like v3.1.2 (Pro) - vBulletin Mods & Addons Copyright © 2013 DragonByte Technologies Ltd.
vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2013 DragonByte Technologies Ltd. (Resources saved on this page: MySQL 33.33%)

SkyscraperCity - In Urbanity We Trust

Hosted by Blacksun, dedicated to this site too!
Forum server management by DaiTengu