Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Google Maps Overlays

Google Maps


Add a marker to Google Maps


Google Maps - Overlays

An overlay is an object bound to longitude/latitude coordinates on the map, and moves as you drag or zoom the map.

Google Maps API has the following overlays:


Google Maps - Add Marker

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

Markers are designed to be interactive. For example, by default they receive the "click" event, often used to open an info window in an event listener.

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

Example

var

marker

=

new

google

.

maps

.

Marker

(

{

position

:

myCenter

,

}

)

;

marker

.

setMap

(

map

)

;

Try it »


Google Maps - Draggable Marker

The following example introduces 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

)

;

Try it »


Google Maps - Icon

Markers can be displayed with a custom new icon instead of the default icon:

Example

var

marker

=

new

google

.

maps

.

Marker

(

{

position

:

myCenter

,

icon

:

'

pinkball.png

'

}

)

;

marker

.

setMap

(

map

)

;

Try it »


Google Maps - Polyline

The GPolyline object can create linear overlays on the map. GPolyline includes a series of points and creates a series of line segments that connect these points in order.

Polyline supports the following properties:

Example

var

myTrip

=

[

stavanger

,

amsterdam

,

london

]

;

var

flightPath

=

new

google

.

maps

.

Polyline

(

{

path

:

myTrip

,

strokeColor

:

"

#0000FF

"

,

strokeOpacity

:

0.8

,

strokeWeight

:

2

}

)

;

Try it »


Google Maps - Polygon

The GPolygon object is similar to the GPolyline object because they both include a series of ordered points. However, unlike a polyline which has two endpoints, a polygon is designed to define a closed region.

Like polylines, you can customize the color, thickness, and transparency of the polygon edges (lines), as well as the color and transparency of the enclosed fill area. Colors should be hexadecimal numbers in HTML style.

Polygon supports 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

}

)

;

Try it »


Google Maps - Circle

Circle supports 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

}

)

;

Try it »


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

)

;

Try it »


Google Maps - Overlay Reference Manual

Google Maps API Reference Manual.