/*
* Google Map Application (GMApp)
* Author: Tane Piper (digitalspaghetti@gmail.com)
* With special thanks Dave Cardwell (who helped BIG TIME on getting this plugin to work).
* Website: http://digitalspaghetti.tooum.net
* Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*
* === Changelog ===
* Version 1.0
* Initial version
* Creates Google Map
* Basic Example: $('#gmap').gmapp();
* Add points to map
* Basic Example: $('#gmap').addPoint('55.948286','-3.200111');
* Takes address or postcode, Geocodes and centers map. Also creates a draggable marker
* === Instructions ===
* Create your div and form. The form submit button must be called id="findaddress".
* 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.
*/
(function($) {
function searchAddress(gmapp, address, GGeocoder, infoarea, settings) {
GGeocoder.getLatLng(address, function(point){
if (!point) {
alert(address + " not found");
} else {
gmapp.setCenter(point,settings.zoom);
var marker = new GMarker(point, {draggable: true});
gmapp.addOverlay(marker);
marker.openInfoWindowHtml("Lat: " + point.lat() + " Lng: " + point.lng());
GEvent.addListener(marker, "dragend", function(){
mylocation = marker.getPoint();
marker.openInfoWindowHtml("Latitude: " + mylocation.lat() + "
Longitude: " + mylocation.lng());
});
}
});
};
$.fn.extend({
gmapp: 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(){
var gmapp = 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('
Google Map Application Version ' + version + '
');*/ /* Seach for the lat & lng of our address*/ jQuery('#findaddress').bind('click', function(){ searchAddress(gmapp, jQuery(settings.geocode).attr('value'), GGeocoder, infoarea, settings); }); }); } }, GMap2: function() { return this[0].GMap2; }, addPoint: function(pointlat, pointlng, pointhtml, isdraggable) { var marker = new GMarker(new GLatLng(pointlat,pointlng), { draggable: isdraggable } ); GEvent.addListener(marker, "click", function(){ marker.openInfoWindowHtml(pointhtml); }); return this[0].GMap2.addOverlay(marker); } }); })(jQuery);