Google Maps Javascript

August 24, 2018
Load Map, Add Marker, Zoom To Marker

Get API Key and Include Javascript for Google Map/Places.

Load Map

<div id="map" style="height: 300px;"></div>
const mapCenter = new google.maps.LatLng(-33.8617374,151.2021291)

const map = new google.maps.Map(document.getElementById('map'), {
  center: mapCenter,
  zoom: 15
})

Place Marker

const marker = new google.maps.Marker({ position: new google.maps.LatLng(-33.8617374,151.2021291), map: map, title: "Test" })

Move Marker and Pan Map

const newLocation = new google.maps.LatLng(35.652832,139.839478)

marker.setPosition(newLocation)
marker.setTitle('Tokyo')

map.panTo(newLocation)
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.