Skip to content

Commit ee55a95

Browse files
committed
feat: add method to set location
1 parent f62d081 commit ee55a95

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/location-picker.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import MapOptions = google.maps.MapOptions
22
import Map = google.maps.Map
33

44
import './location-picker.css'
5+
import LatLng = google.maps.LatLng
56

67
export default class LocationPicker {
78
element: HTMLElement | null
@@ -49,6 +50,15 @@ export default class LocationPicker {
4950
}
5051
}
5152

53+
getMarkerPosition() {
54+
const latLng = this.map.getCenter()
55+
return { lat: latLng.lat(), lng: latLng.lng() }
56+
}
57+
58+
setLocation(lat: number, lng: number) {
59+
this.map.setCenter(new google.maps.LatLng(lat, lng))
60+
}
61+
5262
setCurrentPosition() {
5363
if (navigator.geolocation) {
5464
navigator.geolocation.getCurrentPosition(
@@ -67,11 +77,6 @@ export default class LocationPicker {
6777
console.log('Your browser does not support Geolocation.')
6878
}
6979
}
70-
71-
getMarkerPosition() {
72-
const latLng = this.map.getCenter()
73-
return { lat: latLng.lat(), lng: latLng.lng() }
74-
}
7580
}
7681

7782
export interface LocationPickerOptions {

0 commit comments

Comments
 (0)