Page 1 of 1

Embedding Maps

Posted: Thu Apr 13, 2017 9:33 pm
by wbs
/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?

Re: PHP script for embedding Google Maps

Posted: Thu Apr 13, 2017 10:12 pm
by Tata

Re: PHP script for embedding Google Maps

Posted: Fri Apr 14, 2017 10:24 am
by cmb
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.

Re: PHP script for embedding Google Maps

Posted: Fri Apr 14, 2017 10:32 am
by wbs
Ok, the Iframe solution is really easier than a php function that puts in an iframe. :D
Thanks.

Re: Embedding Google Maps

Posted: Sat Apr 15, 2017 7:38 am
by Tata
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).

Re: Embedding Google Maps

Posted: Thu Nov 23, 2017 1:05 am
by wbs
I've tried using Openstreetmaps iframe, but it just shows a blank object... Can you guys embed Openstreetmaps?

Re: Embedding Google Maps

Posted: Thu Nov 23, 2017 11:08 am
by cmb
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.

Re: Embedding Google Maps

Posted: Thu Nov 23, 2017 11:28 am
by frase
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.

Re: Embedding Maps

Posted: Thu Nov 23, 2017 12:14 pm
by wbs
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.