jQuery(function ($) { $.fn.mappa = function( method ) { // Method calling logic if ( methods[method] ) { return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); } else if ( typeof method === 'object' || ! method ) { return methods.init.apply( this, arguments ); } else { $.error( 'Method ' + method + ' does not exist on jQuery.mappa' ); } }; var methods = { show: function(latitudine,longitudine,indirizzo,contenuto){ if(latitudine != '0.000000' && longitudine != '0.000000'){ this.mappa('init',new google.maps.LatLng(latitudine,longitudine),contenuto); } else{ var geocoder = new google.maps.Geocoder(); var self = this; geocoder.geocode( { 'address': indirizzo }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { self.mappa('init',results[0].geometry.location,contenuto); } else{ self.mappa('init',new google.maps.LatLng(42.945, 12.702),contenuto); } } ); } }, init: function(latlng,contenuto){ var options = { zoom:14, center:latlng, panControl:true, zoomControl:true, scaleControl:true, mapTypeId: google.maps.MapTypeId.ROADMAP }; var id_map = this.attr("id"); var map = new google.maps.Map(document.getElementById(id_map),options); var marker_icon = new google.maps.MarkerImage( '../www.overplace.com/templates/default/site/images/ovp_marker.png', new google.maps.Size(24, 32), null, new google.maps.Point(12, 32), null ); var marker_shadow = new google.maps.MarkerImage( '../www.overplace.com/templates/default/site/images/ovp_marker_shadow.png', new google.maps.Size(44, 32), null, new google.maps.Point(12, 32), null ); var marker = new google.maps.Marker({ map: map, position: latlng, icon: marker_icon, shadow: marker_shadow }); google.maps.event.addListener(marker,'click',function(){ var info_window = new google.maps.InfoWindow({content:contenuto}); info_window.setPosition(latlng); info_window.open(map,marker); }); } } }); jQuery(document).ready(function(){ // var ovp_mappa_options = {} compilato da wordpress; jQuery('#ovp-mappa').mappa('show', ovp_mappa_options.latitudine, ovp_mappa_options.longitudine, ovp_mappa_options.indirizzo, ovp_mappa_options.contenuto); });