Embedding Maps

A place for general not CMSimple related discussions
Post Reply
wbs
Posts: 122
Joined: Sun Apr 02, 2017 8:05 am

Embedding Maps

Post by wbs » Thu Apr 13, 2017 9:33 pm

/edit: Ok, this is bullcrap, just use Google's "share" Iframe code.

Is this function well done? I found it on the internet and the output looks fine.

Code: Select all

function rockable_googlemap($atts, $content = null) {
   extract(shortcode_atts(array(
               "width" => '940',
               "height" => '300',
               "src" => ''
   ), $atts));

return '<div>
         <iframe src="'.$src.'&output=embed" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="'.$width.'" height="'.$height.'"></iframe>
        </div>
       ';
}
Is there a better way to integrate google maps?
Last edited by wbs on Thu Nov 23, 2017 12:07 pm, edited 2 times in total.

Tata
Posts: 3586
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: PHP script for embedding Google Maps

Post by Tata » Thu Apr 13, 2017 10:12 pm

CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: PHP script for embedding Google Maps

Post by cmb » Fri Apr 14, 2017 10:24 am

wbs wrote:Is this function well done? I found it on the internet and the output looks fine.
Hm, this code is supposed to fail in CMSimple_XH, because shortcode_atts() isn't defined. A more reasonable alternative for CMSimple_XH:

Code: Select all

function googlemap($src, $width = 940, $height = 300) {

return '<div>
         <iframe src="'.$src.'&output=embed" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="'.$width.'" height="'.$height.'"></iframe>
        </div>
       ';
}
This can be called on a page in either of the following ways:

Code: Select all

{{{googlemap 'URL'}}}
{{{googlemap 'URL', WIDTH, HEIGHT}}}
wbs wrote:Is there a better way to integrate google maps?
It depends. If you just want a single map, it's probably easiest to get the Code from Google Maps and insert it directly.

If you need more fancy stuff, consider Tata's suggestion or GXRoute.
Christoph M. Becker – Plugins for CMSimple_XH

wbs
Posts: 122
Joined: Sun Apr 02, 2017 8:05 am

Re: PHP script for embedding Google Maps

Post by wbs » Fri Apr 14, 2017 10:32 am

Ok, the Iframe solution is really easier than a php function that puts in an iframe. :D
Thanks.

Tata
Posts: 3586
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: Embedding Google Maps

Post by Tata » Sat Apr 15, 2017 7:38 am

I have tested the above mentioned Jerry's plugin. It offers really nice possibilities. There is stated in documentation:
...
The map size and other configuration parameters can be changed by preceding a call to googlemaps(...) with a call to function googlemaps_config ("config_parameter", "value") before plugin call, f.ex.:
{ [{Googlemaps_config ("mapsize_height", "600");}}}
{ {{Google Maps (51.508742, -0.120850);}}}
...
I tried this and it works fine. In the index.php you may find (about #73):

Code: Select all

$o.='<div id="googleMap'.$gmapId.'" style="width:'.$plugin_cf['googlemaps']['mapsize_width'].'px;height:'.$plugin_cf['googlemaps']['mapsize_height'].'px;"></div>'."\n";
It means the dimension to be put without "px", as this is added in the php. In this case the map can't be show responsive. I tried to put dimensions in "%" and it works even without changing the index.php code. The map is responsive now.Try this:

Code: Select all

{{{GoogleMaps_config ("mapsize_width","100%");}}}
{{{GoogleMaps_config ("mapsize_height","300");}}}
{{{GoogleMaps (49.000842, 20.748526);}}}
or

Code: Select all

{{{GoogleMaps_config ("mapsize_width","100%","mapsize_height","300");}}}
{{{GoogleMaps(49.000842, 20.748526);}}} 
The height cant be defined only in px (without "px" in the plpugin call).
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

wbs
Posts: 122
Joined: Sun Apr 02, 2017 8:05 am

Re: Embedding Google Maps

Post by wbs » Thu Nov 23, 2017 1:05 am

I've tried using Openstreetmaps iframe, but it just shows a blank object... Can you guys embed Openstreetmaps?

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Embedding Google Maps

Post by cmb » Thu Nov 23, 2017 11:08 am

wbs wrote:I've tried using Openstreetmaps iframe, but it just shows a blank object... Can you guys embed Openstreetmaps?
Hm, I've just inserted the following code in a CMSimple_XH 1.7.1 page (with the default editor):

Code: Select all

<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://www.openstreetmap.org/export/embed.html?bbox=7.703475952148438%2C49.87339770318921%2C7.963027954101563%2C50.01038671874375&layer=mapnik" style="border: 1px solid black"></iframe><br/><small><a href="http://www.openstreetmap.org/#map=12/49.9419/7.8333">Größere Karte anzeigen</a></small>
Works fine.
Christoph M. Becker – Plugins for CMSimple_XH

frase
Posts: 5085
Joined: Thu Apr 21, 2016 6:32 am
Location: Saxony
Contact:

Re: Embedding Google Maps

Post by frase » Thu Nov 23, 2017 11:28 am

Besser ist es, den iFrame reponsive einzubinden.
Dazu packt man den iFrame in einen <div> mit der gewünschten Größe mit Breite in %.
Dann bekommt der iFrame Höhe "auto" und Breite "100%".
Ungefähr so;

Code: Select all

<div style="width: 100%; height: 350px;">
<iframe style="border: 1px solid black;" src="http://www.openstreetmap.org/export/embed.html?bbox=7.703475952148438%2C49.87339770318921%2C7.963027954101563%2C50.01038671874375&layer=mapnik" width="100%" height="auto" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe><br>
<small><a href="http://www.openstreetmap.org/#map=12/49.9419/7.8333">Größere Karte anzeigen</a></small>
</div> 
Nachtrag:
Interessant!
FF 57 meldet für "embed.html":
Speicherverbrauch von "will-change" ist zu hoch. Die Budget-Grenze ist die Fläche des Dokuments multipliziert mit 3 (93450 px). Vorkommen von "will-change", die das Budget überschreiten, werden ignoriert.
"embed.html" stammt von Open Street Map.

wbs
Posts: 122
Joined: Sun Apr 02, 2017 8:05 am

Re: Embedding Maps

Post by wbs » Thu Nov 23, 2017 12:14 pm

The code doesn't work in Firefox and Chromium on my system.

/edit: Ah well, I was using http on a https Website so it didn't load "mixed conted". Now it's working, thanks for the help.

Post Reply