function google_map_shortcode($atts) { $atts = shortcode_atts(array('address' => false, 'scrollwheel' => 'true', 'zoom' => false, 'lat' => false, 'long' => false, 'desc' => false, 'icon' => false, 'width' => '100%', 'height' => '400px', 'mapcontrols' => 'false'), $atts); $address = $atts['address']; $zoom = $atts['zoom']; $desc = $atts['desc']; $icon = $atts['icon']; $lat = $atts['lat']; $long = $atts['long']; if ($address != "") { if ($address && wp_script_is('google-map-script-api', 'registered')) { wp_print_scripts('google-map-script-api'); $coordinates = google_map_get_coordinates($address); if (!is_array($coordinates)) { return; } $map_id = uniqid('google_map_'); // generate a unique ID for this map ob_start(); ?> <div class="google_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 pw_run_map_<?php echo $map_id; ?> (){ var location = new google.maps.LatLng("<?php echo $coordinates['lat']; ?> ", "<?php echo $coordinates['lng']; ?> "); var map_options = { zoom: <?php if ($zoom != "") { echo $zoom; } else { echo "15"; } ?> , center: location, scrollwheel: <?php echo 'true' === strtolower($atts['scrollwheel']) ? '1' : '0'; ?> , disableDefaultUI: <?php echo 'true' === strtolower($atts['mapcontrols']) ? '1' : '0'; ?> , mapTypeId: google.maps.MapTypeId.ROADMAP } var 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 $icon; ?> ", title:"<?php echo $desc; ?> " }); <?php if ($desc != "") { ?> var infowindow = new google.maps.InfoWindow({ content: "<?php echo $desc; ?> " }); google.maps.event.addListener(marker, "click", function() { infowindow.open(map_<?php echo $map_id; ?> , marker); }); <?php } ?> } pw_run_map_<?php echo $map_id; ?> (); </script> <?php return ob_get_clean(); } } elseif ($lat != "" && $long != "" && wp_script_is('google-map-script-api', 'registered')) { wp_print_scripts('google-map-script-api'); $map_id = uniqid('google_map_'); // generate a unique ID for this map ob_start(); ?> <div class="google_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 pw_run_map_<?php echo $map_id; ?> (){ var location = new google.maps.LatLng("<?php echo $lat; ?> ", "<?php echo $long; ?> "); var map_options = { zoom: <?php if ($zoom != "") { echo $zoom; } else { echo "15"; } ?> , center: location, scrollwheel: <?php echo 'true' === strtolower($atts['scrollwheel']) ? '1' : '0'; ?> , disableDefaultUI: <?php echo 'true' === strtolower($atts['mapcontrols']) ? '1' : '0'; ?> , mapTypeId: google.maps.MapTypeId.ROADMAP } var 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 $icon; ?> ", title:"<?php echo $desc; ?> " }); <?php if ($desc != "") { ?> var infowindow = new google.maps.InfoWindow({ content: "<?php echo $desc; ?> " }); google.maps.event.addListener(marker, "click", function() { infowindow.open(map_<?php echo $map_id; ?> , marker); }); <?php } ?> } pw_run_map_<?php echo $map_id; ?> (); </script> <?php return ob_get_clean(); } else { return __('Please check your latitude and longitude OR address in shortcode.', 'google_map'); } }
function google_map($atts, $content = null) { extract(shortcode_atts(array('address' => false, 'width' => '100%', 'height' => '400px'), $atts)); global $up_options; $address = $up_options->office_location; if ($address) { wp_print_scripts('google-maps-api'); $coordinates = google_map_get_coordinates($address); // var_dump($coordinates); if (!is_array($coordinates)) { return; } $map_id = uniqid('google_map_'); ob_start(); ?> <div class="google_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("30.25459", "-81.58827"); var location = new google.maps.LatLng("<?php echo $coordinates['lat']; ?> ", "<?php echo $coordinates['lng']; ?> "); var map_options = { zoom: 15, center: location, scrollwheel: false, 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(); }