function ale_map($atts, $content = null) { extract(shortcode_atts(array('address' => false, 'widht' => '100%', 'height' => '400px'), $atts)); $address = $atts['address']; if ($address) { wp_print_scripts('google-maps-api'); $coordinates = ale_map_get_coordinates($address); if (!is_array($coordinates)) { return; } $map_id = uniqid('ale_map_'); ob_start(); ?> <div class="ale_map_canvas" id="<?php echo esc_attr($map_id); ?> " style="height: <?php echo esc_attr($atts['height']); ?> ; width: <?php echo esc_attr($atts['width']); ?> "></div> <script type="text/javascript"> var map_<?php echo $map_id; ?> ; function ale_run_map_<?php echo $map_id; ?> (){ var location = new google.maps.LatLng("<?php echo $coordinates['lat']; ?> ", "<?php echo $coordinates['lng']; ?> "); var map_options = { zoom: 15, center: location, mapTypeId: google.maps.MapTypeId.ROADMAP } map_<?php echo $map_id; ?> = new google.maps.Map(document.getElementById("<?php echo $map_id; ?> "), map_options); var marker = new google.maps.Marker({ position: location, map: map_<?php echo $map_id; ?> }); } ale_run_map_<?php echo $map_id; ?> (); </script> <?php } return ob_get_clean(); }
function ale_map($atts, $content = null) { extract(shortcode_atts(array('address' => false, 'widht' => '100%', 'height' => '400px'), $atts)); $address = $atts['address']; if ($address) { wp_print_scripts('google-maps-api'); $coordinates = ale_map_get_coordinates($address); if (!is_array($coordinates)) { return; } $map_id = uniqid('ale_map_'); ob_start(); ?> <div class="ale_map_canvas" id="<?php echo esc_attr($map_id); ?> " style="height: <?php echo esc_attr($atts['height']); ?> ; width: <?php echo esc_attr($atts['width']); ?> "></div> <script type="text/javascript"> var map_<?php echo $map_id; ?> ; function ale_run_map_<?php echo $map_id; ?> (){ var location = new google.maps.LatLng("<?php echo $coordinates['lat']; ?> ", "<?php echo $coordinates['lng']; ?> "); var map_options = { zoom: 11, center: location, styles: [{"featureType":"water","stylers":[{"visibility":"on"},{"color":"#b5cbe4"}]},{"featureType":"landscape","stylers":[{"color":"#efefef"}]},{"featureType":"road.highway","elementType":"geometry","stylers":[{"color":"#83a5b0"}]},{"featureType":"road.arterial","elementType":"geometry","stylers":[{"color":"#bdcdd3"}]},{"featureType":"road.local","elementType":"geometry","stylers":[{"color":"#ffffff"}]},{"featureType":"poi.park","elementType":"geometry","stylers":[{"color":"#e3eed3"}]},{"featureType":"administrative","stylers":[{"visibility":"on"},{"lightness":33}]},{"featureType":"road"},{"featureType":"poi.park","elementType":"labels","stylers":[{"visibility":"on"},{"lightness":20}]},{},{"featureType":"road","stylers":[{"lightness":20}]}], mapTypeId: google.maps.MapTypeId.ROADMAP } map_<?php echo $map_id; ?> = new google.maps.Map(document.getElementById("<?php echo $map_id; ?> "), map_options); var marker = new google.maps.Marker({ position: location, map: map_<?php echo $map_id; ?> , icon: "<?php echo get_bloginfo('template_directory'); ?> /css/images/icon-map.png" }); } ale_run_map_<?php echo $map_id; ?> (); </script> <?php } return ob_get_clean(); }