Skip to content

Instantly share code, notes, and snippets.

View timdeschryver's full-sized avatar
👟

Tim Deschryver timdeschryver

👟
View GitHub Profile
Property Description
title Sets the title, visible on hover
position Sets the position
label Sets the label
clickable If the marker should listen to mouse and touch events, default is true
options Sets the options, for more info see the [docs](https://developers.
export class AppComponent implements OnInit {
addMarker() {
this.markers.push({
position: {
lat: this.center.lat + ((Math.random() - 0.5) * 2) / 10,
lng: this.center.lng + ((Math.random() - 0.5) * 2) / 10,
},
label: {
color: 'red',
text: 'Marker label ' + (this.markers.length + 1),
<google-map>
<map-marker
*ngFor="let marker of markers"
[position]="marker.position"
[label]="marker.label"
[title]="marker.title"
[options]="marker.options"
>
</map-marker>
</google-map>
export class AppComponent implements OnInit {
@ViewChild(MapInfoWindow, { static: false }) info: MapInfoWindow
logCenter() {
console.log(JSON.stringify(this.map.getCenter()))
}
}
Function Description
fitBounds Sets the viewport to contain the given bounds
panBy Changes the center of the map by the given distance in pixels
panTo Changes the center of the map to the given LatLng
panToBounds Pans the map by the minimum amount necessary to contain the given LatLngBounds
getBounds Returns the lat/lng bounds of the current viewport
getCenter Returns the position displa
export class AppComponent implements OnInit {
click(event: google.maps.MouseEvent) {
console.log(event)
}
}
<google-map (mapClick)="click($event)"></google-map>
Property JavaScript API Method Description
boundsChanged bounds_changed This event is fired when the viewport bounds have changed
centerChanged center_changed This event is fired when the map center property changes
mapClick click This event is fired when the user clicks on the map
mapDblclick dblclick This event is fired when the user double-clicks on the map. Note that the click event will also fire, righ
export class AppComponent implements OnInit {
zoom = 12
center: google.maps.LatLngLiteral
options: google.maps.MapOptions = {
mapTypeId: 'hybrid',
zoomControl: false,
scrollwheel: false,
disableDoubleClickZoom: true,
maxZoom: 15,
minZoom: 8,
<google-map></google-map>