Embedding Google Maps

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

Embedding Google Maps

Postby 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 Fri Apr 14, 2017 10:33 am, edited 1 time in total.

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

Re: PHP script for embedding Google Maps

Postby 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: 11442
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: PHP script for embedding Google Maps

Postby 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, but not for CMSimple 4+

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

Re: PHP script for embedding Google Maps

Postby 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: 2359
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: Embedding Google Maps

Postby 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.


Return to “General Discussions & Announcements”

Who is online

Users browsing this forum: No registered users and 2 guests