Skip to content

Instantly share code, notes, and snippets.

@dorianmariecom
Created April 12, 2021 21:38
Show Gist options
  • Select an option

  • Save dorianmariecom/687d416473fadce59821046e4f7eef82 to your computer and use it in GitHub Desktop.

Select an option

Save dorianmariecom/687d416473fadce59821046e4f7eef82 to your computer and use it in GitHub Desktop.
import { Controller } from "stimulus"
export default class extends Controller {
connect() {
if (typeof window.google !== "undefined") {
this.initMap()
}
}
initMap() {
this.map = new window.google.maps.Map(this.element)
this.map.fitBounds(this.details().geometry.viewport)
this.map.setCenter(this.details().geometry.location)
this.marker = new window.google.maps.Marker({ map: this.map })
this.marker.setPosition(this.details().geometry.location)
this.marker.setVisible(true)
}
placeChanged() {
const place = this.autocomplete.getPlace()
if (!place.geometry) {
return
}
this.detailsTarget.value = JSON.stringify(place)
this.updateMarker()
}
details() {
return JSON.parse(this.data.get("details"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment