Deprecated: Assigning the return value of new by reference is deprecated in /home/summarg/domains/summarg.com/public_html/wp-content/plugins/post-series/post-series.php on line 841 Notice: is_feed was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.) in /home/summarg/domains/summarg.com/public_html/wp-includes/functions.php on line 3245 Mostrar un mapa de Google Maps con un marcador mediante shortcodes | SummArg

SummArg | Cursos y recursos para webmasters

18/09/2011

Mostrar un mapa de Google Maps con un marcador mediante shortcodes

Mediante el siguiente código podemos añadir un mapa de Google Maps con un marcador a través de shortcodes. Primero debemos solicitar una Key en http://code.google.com/intl/es/apis/maps/signup.html. Luego insertamos el siguiente código en nuestro archivo functions.php

function googlemap_shortcode( $atts ) {
    extract(shortcode_atts(array(
        'width' => '500px',
        'height' => '300px',
        'apikey' => 'REPLACEME',
        'marker' => '',
        'center' => '',
        'zoom' => '13'
    ), $atts));
    if ($center) $setCenter = 'map.setCenter(new GLatLng('.$center.'), '.$zoom.');';
    if ($marker) $setMarker = 'map.addOverlay(new GMarker(new GLatLng('.$marker.')));';
    $rand = rand(1,100) * rand(1,100);
    return '
    	<script src="http://maps.google.com/maps?file=api&v=2.x&sensor=false&key='.$apikey.'" type="text/javascript"></script>
	    <script type="text/javascript">
		    function initialize() {
		      if (GBrowserIsCompatible()) {
		        var map = new GMap2(document.getElementById("map_canvas_'.$rand.'"));
		        '.$setCenter.'
		        '.$setMarker.'
		        map.setUIToDefault();
		      }
		    }
		    initialize();
	    </script>
    ';
}
add_shortcode('googlemap', 'googlemap_shortcode');

En el shortcode pasaremos los parámetros zoom, center, marker y width de la siguiente manera:

[googlemap zoom="13" center="52.66389056542801, 0.1641082763671875" marker="52.66389056542801, 0.1641082763671875" width="488px"]

y el resultado:

Visto en blue-anvil

 

Dejar un comentario

Notice: Undefined variable: wp_sh_class_name in /home/summarg/domains/summarg.com/public_html/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1002 Notice: Undefined variable: wp_sh_class_name in /home/summarg/domains/summarg.com/public_html/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1002 Notice: Use of undefined constant XML - assumed 'XML' in /home/summarg/domains/summarg.com/public_html/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048