Skip to content
This repository has been archived by the owner on Jun 7, 2019. It is now read-only.

piwko28/GoogleMaps_Plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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:
    • addressString — Real address or geographic position "lat, lng" to place marker on it
    • successCallbackfunction(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
    • optionsObject — Marker additional options (see google.maps.Marker at Google Maps API Documentation)
    • imageString — 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:
    • addressesArray<String> — Array of real addresses or geographic positions "lat, lng" to place marker on it
    • successCallbackfunction(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
    • optionsObject — Marker additional options (see google.maps.Marker at Google Maps API Documentation)
    • imageString — 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
    • zoomInteger — Zoom multiplier
    • successCallbackfunction(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
    • ObjectObject — 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:
    • fromMarker — From marker
    • toMarker — Destination marker
    • successCallbackFunction — callback on success
    • errorCallbackFunction — Callback on error
    • optionsObject — request options (see: maps api)
    • rendererOptionsObject — 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:
    • pointsArray<Marker,String> — Array of markers or/and geographical positions "lat, lng" or verticles of polygon
    • optionsObject — 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:
    • fromMarkerMarker — Destination marker
    • markersArray<Marker> — Array of markers to sort
    • callbackfunction(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)
    • precislyInteger — If is positive, it's number of nearest points (by air), which will be checked by google maps service; workaround for google maps limitations
    • optionsObject — Distance Matrix options, see google.maps.DistanceMatrixOptions at Google Maps API Documentation

setInfoWindowAtMarker(marker, info, options, name)

Set info window at marker

  • Parameters:
    • markerMarker — Marker for info window
    • infoString — HTML content to show in info window
    • optionsObject — Info window options (see google.maps.InfoWindowOptions at Google Maps API Documentation)
    • nameString — 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:
    • markerMarker — Marker for info window
    • infoString — HTML content to show in info window
    • optionsObject — Info window options (see google.maps.InfoWindowOptions at Google Maps API Documentation)
    • closeOthersBoolean — 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:
    • markerMarker — Marker object (get from addMarker)
    • clickfunction(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: stylesArray<Object> — Array of objects with Google Maps styles notation
  • Example:
map.setStyle([ { "stylers": [ { "gamma": 0.38 } ] } ]);

About

Easier way to quickly create google map with jQuery

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published