Getting started...
...with gMap is very easy. Simply follow these steps and you're ready to go!
Requirements
To use jquery.gMap simply include jQuery and Google Maps scripts. Using CDN versions sounds like good idea:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.1.min.js" type="text/javascript"></script>
Installation
Download the latest version of gMap and include the Google Maps API along with jQuery and gMap at the page bottom, just before </body> tag (it is good for page loading process).
<script src="/scripts/jquery.gmap.min.js" type="text/javascript"></script>
HTML structure
The HTML structure is quite simple too. Just place a <div> somewhere on your page, style it with CSS (don't forget to assign a fixed width & height) and give it a unique ID or class. If you need a placeholder for browsers not supporting google maps, place any text in div. It will be removed if load succeeds.
<div id="map">Placeholder in case of loading failure</div>
Creating a map
Select the new div element using jQuery's selectors and call the gMap() function on it. I recommend to call the function as soon as the DOM is ready. Please refer to jQuery Events/ready for further infomation.
$(window).ready(function () {
$('#map').gMap();
});
Customizing
gMap can be customized in many different ways. All you need to do is to pass a JSON object to the gMap() function. Please see other tabs for a complete list of properties that can be passed. Options marked red are highly recommended.
Warning! Geocoding (address option) is intended for only few markers and basic setup. Since every marker needs a request, Google allows only limited (probably 10) geocodings. To improve performance always store lat/lng in your database (preferably in numeric(15,12) format).
Main
These are most general options affecting the whole map.
| option | type | default | since |
|---|---|---|---|
| log | boolean | false | 3.0.0 |
| If you need some info in your javascript console, set it to true. Logs geocoding errors and adding markers and others. | |||
| latitude | float/'fit' | 0 | -/3.2.0 |
|
Point on which the viewport will be centered. See: centering rules. Using 'fit' option will calculate center to show all the markers. It may fail combined with address-based markers. | |||
| longitude | float/'fit' | 0 | -/3.2.0 |
| Point on which the viewport will be centered. See: centering rules. Using 'fit' option will calculate center to show all the markers. It may fail combined with address-based markers. | |||
| address | string | "" | 1.1.0 |
| Address on which the viewport will be centered. See: centering rules | |||
| zoom | integer/'fit' | 3 | -/3.2.0 |
| Zoom value from 1 to 19 where 19 is the greatest and 1 the smallest. Using 'fit' option will calculate zoom to show all the markers. It may fail combined with address-based markers. | |||
| minZoom | integer | - | 3.2.0 |
| Min allowed zoom value | |||
| maxZoom | integer | - | 3.2.0 |
| Max allowed zoom value | |||
| maptype | - | google.maps.MapTypeId.ROADMAP | changed in 3.0.0 |
|
Predefined variable for setting the map type.
Please refer to the Google Maps API for possible values. | |||
Controls
| option | type | default | since | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| mapTypeControl | boolean | true | 3.0.0 | ||||||||||||||||||||
|
The MapType control lets the user toggle between map types (such as ROADMAP and SATELLITE). Please refer to Google Maps API for more information. | |||||||||||||||||||||||
| zoomControl | boolean | true | 3.0.0 | ||||||||||||||||||||
|
The Zoom control displays a slider (for large maps) or small "+/-" buttons (for small maps) to control the zoom level of the map. Please refer to Google Maps API for more information. | |||||||||||||||||||||||
| panControl | boolean | false | 3.0.0 | ||||||||||||||||||||
|
The pan control displays buttons for panning the map. Please refer to Google Maps API for more information. | |||||||||||||||||||||||
| scaleControl | boolean | false | 3.0.0 | ||||||||||||||||||||
|
The scale control displays a map scale element. Please refer to Google Maps API for more information. | |||||||||||||||||||||||
| streetViewControl | boolean | true | 3.0.0 | ||||||||||||||||||||
|
The Street View control contains a Pegman icon which can be dragged onto the map to enable Street View. Please refer to Google Maps API for more information. | |||||||||||||||||||||||
| controlsPositions | object | {} | 3.3.2 | ||||||||||||||||||||
Positions of 5 default controls. Possible values are:
| |||||||||||||||||||||||
| controlsStyle | object | {} | 3.3.2 | ||||||||||||||||||||
Special style of control. Described in Google Maps API.
| |||||||||||||||||||||||
| controls | array | [] | changed in 3.0.0 | ||||||||||||||||||||
List of additional controls on the map. Actually you shouldn't use it if you don't have to.
It's not related to V2 controls array and is intended for advanced users only.
Use above 5 booleans to set standard controls.
| |||||||||||||||||||||||
| scrollwheel | boolean | true | - | ||||||||||||||||||||
| Set to false to disable zooming with your mouses scrollwheel. | |||||||||||||||||||||||
Route finder
| option | type | default | since | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| routeFinder | object | 3.3.0 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Warning! Geocoding (address option) is intended for only few markers and basic setup. Since every marker needs a request, Google allows only limited (probably 10) geocodings. To improve performance always store lat/lng in your database (preferably in numeric(15,12) format).
Marker specific
| option | type | default | since | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| markers | array | [] | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
List of points to be marked on the map. Every entry in this array has to be in object.
If at least one entry is given the viewport will be centered to the first point/address. Every entry contains the following properties:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Global
| option | type | default | since | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| html_prepend | string | <div class="gmap_marker"> | 1.0.1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| HTML string to get prepended to a marker's info window. Useful for styling through CSS. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| html_append | string | <div class="gmap_marker"> | 1.0.1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| HTML string to get appended to a marker's info window. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| icon | json | - | - | ||||||||||||||||||||||||||||||||||||||||||||||||
Subset of properties for defining a custom marker image for all markers.
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| singleInfoWindow | boolean | true | 3.1.0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| This setting forces only one infowindow open at the time. It's enabled by default, to correspond with default (and only) setting in V2 API. | |||||||||||||||||||||||||||||||||||||||||||||||||||
Callbacks
| option | type | default | since |
|---|---|---|---|
| onComplete | function | function(){} | 3.1.0 |
| Function called after loading of all markers. It's useful while using geocoding, when you have to wait for all requests to complete. | |||
Additional functions
Additional functions may be called on gMap enabled element. Use syntax:
$("#map").gmap("function name", argument1, argument2, ...);
using any function name given below. Examples were provided with possible arguments and ideas for usage.
| option | arguments | since | |
|---|---|---|---|
| addMarker | marker configuration | 3.2.0 | |
| |||
| addMarkers | marker configuration array | 3.2.0 | |
Shorthand for multiple markers adding.
| |||
| removeAllMarkers | none | 3.2.0 | |
| |||
| getMarker | marker key | 3.2.0 | |
| |||
| fixAfterResize | boolean | 3.3.0 | |
To make life easier, there is a new function fixing all issues described in examples.
Call $('#map').gMap('fixAfterResize'); or $('#map').gMap('fixAfterResize', true); to fix resized map. Optional flag (true) enables ugly hack for rapid centering instead of default, smooth one.
| |||
| setZoom | zoomlevel | 3.3.0 | |
| |||
| changeSettings | config object | 3.3.0 | |
Designed to let you change any map settings. Currently tested with: latitude, longitude, zoom.
| |||
| mapclick | callback | 3.3.0 | |
Callback will be called if user clicks on map. LatLng object will be passed as an argument.
| |||
| geocode | address, callback | 3.3.0 | |
Geocodes given address and calls a callback with latlng as an argument.
Extremaly useful if you need to turn your address coded database into lat/lng coordinates.
| |||
| getRoute | object with options: {to, from, routeDisplay} | 3.3.0 | |
Takes two lat/lng and calculates route, shows steps in routeDisplay element. Uses configuration object routeFinder.
| |||
Handling gmap after initialisation
I understand that this plugin is best for initial displaying of markers and stuff. If you want to manipulate map later by yourself, simply call:
var gmap = $("#map").data("gmap");
gmap === {
'opts': opts, // plugin options, used internally
'gmap': $gmap, // google map object
'markers': [], // array of markers
'infoWindow': null // currently opened infowindow
};
Note: in 3.0.0 it was $("#map").data("$gmap"); and returned only map object. I found it less extensible
and now it's returning object. However, for backward compatibility, if you call data("$gmap") you will
get map object as in older version. This behaviour may be removed later.
Map centering rules
In 3.0.0 map is centered based on following points:
- address in options
- latitude & longitude in options
- address of marker[0]
- latitude & longitude of marker[0]
- failsafe (0,0)
- latitude & longitude in options
- address in options
- latitude & longitude of first marker having it
- address of first marker
- failsafe (0,0)
API V2
Google Maps API V2 is no longer supported in 3.0.0 version.
Following documentation is for V3 version only. If you need V2 docs please visit http://gmap.nurtext.de/documentation.html.
If you need migration help please visit guide.


