Easy Tutorial
❮ Ref Setmaptypeid Google Maps Events ❯

Google Maps


Add a marker in Google Maps


Google Maps - Overlays

Overlays are objects on the map that are tied to latitude/longitude coordinates, so they move when you drag or zoom the map.

Google Maps API offers several types of overlays:


Google Maps - Adding Markers

Markers identify points on the map. By default, they use G_DEFAULT_ICON (you can also specify a custom icon). The GMarker constructor takes a GLatLng and an optional GMarkerOptions object as parameters.

Add a marker to the map using the setMap() method:

Example

var marker = new google.maps.Marker({
    position: myCenter,
});

marker.setMap(map);

Google Maps - Draggable Markers

The following example shows how to use the animation property to drag a marker:

Example

marker = new google.maps.Marker({
    position: myCenter,
    animation: google.maps.Animation.BOUNCE
});

marker.setMap(map);

Google Maps - Icons

Markers can display custom icons instead of the default icon:

Example

var marker = new google.maps.Marker({
    position: myCenter,
    icon: 'pinkball.png'
});

marker.setMap(map);

Google Maps - Polylines

The GPolyline object creates a linear overlay on the map. GPolyline includes a series of points and creates a series of line segments that connect those points in order.

Polylines support the following properties:

Example

var myTrip = [stavanger, amsterdam, london];
var flightPath = new google.maps.Polyline({
  path: myTrip,
  strokeColor: "#0000FF",
  strokeOpacity: 0.8,
  strokeWeight: 2
});

Google Maps - Polygons

The GPolygon object is similar to the GPolyline object because they both include a series of ordered points. However, polygons are not like polylines with two endpoints; instead, they are designed to define areas that form a closed loop.

Like polylines, you can customize the color, thickness, and opacity of the polygon's edges, as well as the color and opacity of the filled area. Colors should be in hexadecimal HTML style.

Polygons support the following properties:

Example

var myTrip = [stavanger, amsterdam, london, stavanger];
var flightPath = new google.maps.Polygon({
  path: myTrip,
  strokeColor: "#0000FF",
  strokeOpacity: 0.8,
  strokeWeight: 2,
  fillColor: "#0000FF",
  fillOpacity: 0.4
});

Google Maps - Circle

Circles support the following properties:

Example

var myCity = new google.maps.Circle({
  center: amsterdam,
  radius: 20000,
  strokeColor: "#0000FF",
  strokeOpacity: 0.8,
  strokeWeight: 2,
  fillColor: "#0000FF",
  fillOpacity: 0.4
});

Google Maps - Info Window

Display a text info window on a marker:

Example

var infowindow = new google.maps.InfoWindow({
  content: "Hello World!"
});

infowindow.open(map, marker);

Google Maps - Overlay Reference Manual

Google Maps API Reference Manual.

❮ Ref Setmaptypeid Google Maps Events ❯