1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| function googlemap_show(){
//JAVASCIPT
wp_enqueue_script('Google maps','http://maps.googleapis.com/maps/api/js?sensor=false',array('jquery'),'',true);
add_action('wp_footer', 'googlemap_script',30 );
//HTML
echo '
<style>
#map-canvas{
position: relative;
height: 360px;
overflow: hidden;
margin:40px 0;
}
#map-canvas iframe,
#map-canvas object,
#map-canvas embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
</style>
<div id="map-canvas" style="width:100%;"></div>';
}
function googlemap_script(){
?>
<script type="text/javascript">
var geocoder;
var map;
var contentString ='<div class="content"><img alt="contact jrm colors" itemprop="logo" src="<?php bloginfo("template_directory"); ?>/images/jrm-colors-peinture.png" width="120" height="97" style="float:left;height: 97px;width:120px;"><div style="margin-left:130px;padding-top:20px;"><?= get_option('infos_adresse'); ?><br><?= get_option('infos_codepostal'); ?><?= get_option('infos_ville'); ?><br><?= json_encode(get_option('horaire')); ?></div></div>';
function initialize() {
geocoder = new google.maps.Geocoder();
geocoder.geocode( {
address: '<?= get_option('infos_adresse'); ?> <?= get_option('infos_codepostal'); ?> <?= get_option('infos_ville'); ?>, FRANCE',}
, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
draggable:false, //set marker draggable
animation: google.maps.Animation.DROP, //bounce animation
position: results[0].geometry.location
});
var infowindow = new google.maps.InfoWindow({
content: contentString,
maxWidth: 350
});
infowindow.open(map,marker);
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
var mapOptions = {
zoom: 14,
panControl: true, //enable pan Control
zoomControl: true, //enable zoom control
zoomControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU //zoom control size
},
scaleControl: true, // enable scale control
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}
google.maps.event.addDomListener(window, 'resize', initialize);
google.maps.event.addDomListener(window, 'load', initialize);
</script> |
Partager