Created
April 12, 2021 21:38
-
-
Save dorianmariecom/687d416473fadce59821046e4f7eef82 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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