/* * Google Map Application (GMApp) * Author: Tane Piper (digitalspaghetti@gmail.com) * Website: http://digitalspaghetti.tooum.net * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php * * === Changelog === * Version 0.1 * + Initial Version * * === Instructions === * Create your div and form. The form submit button must be called id="findaddress". * Then insert your jQuery to activate (i.e. $('#mydiv').gmapp(); * Now type in the address or postcode to search for the location you like, this will drop * a marker there, which you can drag around. */jQuery.gmapp = { buildApp : function(settings) { var version = "0.1"; /* Default Settings*/ settings = jQuery.extend({ maptype: G_HYBRID_TYPE, center: [55.958858,-3.162302], zoom: 12, control: "small", showtype: true, showoverview: true, infoarea: "#gmapp-info", geocode: "#Address", latfield: "#VenueLatitude", lngfield: "#VenueLongitude", loadpoints: "/venues/" },settings); if (GBrowserIsCompatible()) { return this.each(function(){ this.GMap2 = new GMap2(this); GGeocoder = new GClientGeocoder(); var infoarea = settings.infoarea; this.GMap2.setCenter(new GLatLng(settings.center[0],settings.center[1]),settings.zoom,settings.maptype); switch(settings.control) { case "small": this.GMap2.addControl(new GSmallMapControl()); break; case "large": this.GMap2.addControl(new GLargeMapControl()); break; default: this.GMap2.addControl(new GSmallMapControl()); } if (settings.showtype == true){ this.GMap2.addControl(new GMapTypeControl()); } if (settings.showoverview == true){ this.GMap2.addControl(new GOverviewMapControl()); } /*jQuery(this).after('<p><strong>Google Map Application Version ' + version + '</strong></p>');*/ /* Seach for the lat & lng of our address*/ jQuery('#findaddress').bind('click', function(){ jQuery.gmapp.searchAddress(jQuery(settings.geocode).attr('value'), GGeocoder, infoarea); }); }); } }, searchAddress : function(address, GGeocoder, infoarea) { GGeocoder.getLatLng( address, function(point){ if (!point) { alert(address + " not found"); } else { this.GMap2.setCenter(point,12); var marker = new GMarker(point, {draggable: true}); this.GMap2.addOverlay(marker); marker.openInfoWindowHtml("Lat: " + point.lat() + " Lng: " + point.lng()); GEvent.addListener(marker, "dragend", function(){ mylocation = marker.getPoint(); marker.openInfoWindowHtml("Latitude: " + mylocation.lat() + "<br />Longitude: " + mylocation.lng()); }); } }); }, /* Returns the map being used so Google methods can be accessed*/ /* Example: $("#gmap").GMap2().setCenter(new GLatLng(55.958387,-3.162367), 10);*/ GMap2 : function() { return this[0].GMap2; }, /* FIXME: Add's a point to the current map (this function currently does not give the desired results)*/ /* Example: $("#gmap").addPoint({pointlat:55.958387,pointlnt:-3.162367, pointhtml:"My Point", isdraggable:true});*/ addPoint : function(pointlat, pointlng, pointhtml, isdraggable,centermap) { var marker = new GMarker(new GLatLng(pointlat,pointlng), { draggable: isdraggable } ); return this[0].GMap2.addOverlay(marker); if (centermap == true) { return this[0].GMap2.setCenter(new GLatLng(pointlat,pointlng),10); } }}jQuery.fn.gmapp = jQuery.gmapp.buildApp;jQuery.fn.GMap2 = jQuery.gmapp.GMap2;jQuery.fn.addPoint = jQuery.gmapp.addPoint;