πŸ”” Alert..!! Get 2 Month Free Cloud Hosting With $200 Bonus From Digital Ocean ACTIVATE DEAL

Just another jQuery wrapper for Google Maps API that helps you quickly insert customizable Google Maps on the web page.

Google-Maps

Documentation

jQuery GoogleMaps Plugin

Easier way to quickly create google map with jQuery

Put in head:

<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>

and this file.

Use:

  var map = $("#mapcontainer")    .css({ width : '300px', height : '300px' })    .googlemaps();   var marker = map.setMarkerAtAddress('Wroclaw');   map.setCenterAtMarker(marker, 5);

It means: Center and put a marker on WrocΕ‚aw and zoom it to 5.

See example directory for more.

Documentation

Properties

markers

Array of all placed markers

infowindows

Array of all infowindows

map

Map object (see more at Google Maps API v3)

Methods

setMarker(address, successCallback, errorCallback, options, image)

Place marker at real address on the map

  • Parameters:
    • address β€” String β€” Real address or geographic position "lat, lng" to place marker on it
    • successCallback β€” function(Marker) β€” Function, which is called after geocoding address and put the marker
    • {function(string, β€” errorCallback Function, which is called after error (ex. unknown address); params: status, address
    • options β€” Object β€” Marker additional options (see google.maps.Marker at Google Maps API Documentation)
    • image β€” String β€” Url to image of marker's icon
  • Returns: Object β€” Map plugin itself
  • Example:
var map = $("#map").googlemaps(); map.setMarker( 	"Wroclaw, Poland", 	undefined, 	function() { 		alert('Can't find!'); 	}, 	{ 		visible : false 	} ); map.setMarker("52, 20");

setMarkersAtAddresses(addresses, successCallback, errorCallback, options, images, putMarkerCallback)

Place many markers at real addresses

  • Parameters:
    • addresses β€” Array<String> β€” Array of real addresses or geographic positions "lat, lng" to place marker on it
    • successCallback β€” function(Array<Marker>) β€” Function, which is called after put all markers on the map
    • {function(string, β€” errorCallback Function, which is called after error (ex. unknown address); params: status, address
    • options β€” Object β€” Marker additional options (see google.maps.Marker at Google Maps API Documentation)
    • image β€” String β€” Url to image of marker's icon
    • {function(Marker, β€” putMarkerCallback Function, which is called after geocoding address and put the marker; params: marker, address
  • Returns: Object β€” Map plugin itself
  • Example:
$("#map").googlemaps().setMarkersAtAddresses([   "Polska",   "Niemcy",   "Holandia",   "Ukraina",   "Rosja" ]);

setCenter(address, zoom, successCallback, errorCallback, geocoderoptions)

Center map at real address, geographical coordinates or marker

  • Parameters:
    • {String, β€” Array} address Real address, geographical coordinates (string: "lat, lng"), marker or array of markers to center the map on it
    • zoom β€” Integer β€” Zoom multiplier
    • successCallback β€” function(position:LatLng) β€” Function, which is called after find address, center and zoom
    • {function(status:String, β€” errorCallback Function, which is called after error with finding address
    • Object β€” Object β€” with additional options of geocoder
  • Returns: Object β€” Map plugin itself
  • Example:
var map = $("#map").googlemaps(); map.setMarkerAtAddress( 	"GrabiszyΕ„ska 241, WrocΕ‚aw, Polska", 	function(marker) { 		map.setCenter(marker, 16); 	} );

setRoute(from, to, name, successCallback, errorCallback, options, rendererOptions)

Draw route between two markers on the map.

  • Parameters:
    • from β€” Marker β€” From marker
    • to β€” Marker β€” Destination marker
    • successCallback β€” Function β€” callback on success
    • errorCallback β€” Function β€” Callback on error
    • options β€” Object β€” request options (see: maps api)
    • rendererOptions β€” Object β€” Renderer optins (see: maps api)
  • Example:
var map = $("#map").googlemaps(); map.setMarker( 	"Wroclaw, Poland", 	function(from) { 		map.setMarker( 			"Warszawa, Poland", 			function(to) { 				map.setRoute(from, to, "route1"); 			} 		); 	} );

setPolygon(points, options)

Draw polygon on the maps. Default is red stroke and red fill

  • Parameters:
    • points β€” Array<Marker,String> β€” Array of markers or/and geographical positions "lat, lng" or verticles of polygon
    • options β€” Object β€” Polygon options (see google.maps.PolygonOptions at Google Maps API Documentation)
  • Returns: Polygon β€” google.maps.Polygon
  • Example:
var map = $("#map").googlemaps(); map.setCenter("Polska", 6, function() { 	map.setMarkersAtAddresses( 		[ 			"Warszawa", 			"KrakΓ³w", 			"WrocΕ‚aw" 		], 		function(markers) { 			map.setPolygon([ 				markers[0], 				markers[1], 				markers[2], 				"51, 19", 				markers[0] 			]); 		} 	); });

getDistances(fromMarker, markers, callback, precisly, options)

Sort markers from closest to farest from destination marker

  • Parameters:
    • fromMarker β€” Marker β€” Destination marker
    • markers β€” Array<Marker> β€” Array of markers to sort
    • callback β€” function(markers:Array<Object>,status:String) β€” Returns sorted objects (by distance in kilometers) with fields: marker:Marker, distance:Float, airDistance:Float (by plane, optional), routeDistance:Float (by car, optional), duration:Float (by car in minutes, optional), precisly:Boolean (if checked by google maps)
    • precisly β€” Integer β€” If is positive, it's number of nearest points (by air), which will be checked by google maps service; workaround for google maps limitations
    • options β€” Object β€” Distance Matrix options, see google.maps.DistanceMatrixOptions at Google Maps API Documentation

setInfoWindowAtMarker(marker, info, options, name)

Set info window at marker

  • Parameters:
    • marker β€” Marker β€” Marker for info window
    • info β€” String β€” HTML content to show in info window
    • options β€” Object β€” Info window options (see google.maps.InfoWindowOptions at Google Maps API Documentation)
    • name β€” String β€” Unused at this moment; it should pick right info window from array, when it exists
  • Returns: InfoWindow β€” google.maps.InfoWindow (see Google Maps API Documentation)

setInfoWindowAtMarkerOnClick(marker, info, options, closeOthers)

Set info window at marker on click event at the marker

  • Parameters:
    • marker β€” Marker β€” Marker for info window
    • info β€” String β€” HTML content to show in info window
    • options β€” Object β€” Info window options (see google.maps.InfoWindowOptions at Google Maps API Documentation)
    • closeOthers β€” Boolean β€” Close all opened info windows before show this one
  • Returns: InfoWindow β€” google.maps.InfoWindow (see Google Maps API Documentation)

closeAllInfoWindows()

Close all opened info windows

setMarkerClick(marker, click)

Bind click event to marker

  • Parameters:
    • marker β€” Marker β€” Marker object (get from addMarker)
    • click β€” function(this:Marker) β€” Function, which is called on click at marker
  • Example:
var map = $("#map").googlemaps(); map.setMarker( 	"Wroclaw, Polska", 	function(marker) { 		map.setMarkerClick(marker, function() { 			alert('Marker clicked!'); 		}); 	} );

setStyles(styles)

Change styles of map (ex. colors) Use wizard: http://gmaps-samples-v3.googlecode.com/svn/trunk/styledmaps/wizard/index.html

  • Parameters: styles β€” Array<Object> β€” Array of objects with Google Maps styles notation
  • Example:
map.setStyle([ { "stylers": [ { "gamma": 0.38 } ] } ]);

You May Also Like