aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAubrey-Li <63608597+Aubrey-Li@users.noreply.github.com>2021-07-31 12:36:12 -0700
committerAubrey-Li <63608597+Aubrey-Li@users.noreply.github.com>2021-07-31 12:36:12 -0700
commitd470a08e9ce329f1a6ff9a4591c41e1e04fb62bb (patch)
tree3a45d109bf359f9545ade5b72a84554aaf261af9
parentd714f8ae1940f08283c491b09a1c23127cf04064 (diff)
allow locating user location
-rw-r--r--src/client/views/nodes/MapBox/MapBox.tsx17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/client/views/nodes/MapBox/MapBox.tsx b/src/client/views/nodes/MapBox/MapBox.tsx
index 2b3bcb0a2..6447d9715 100644
--- a/src/client/views/nodes/MapBox/MapBox.tsx
+++ b/src/client/views/nodes/MapBox/MapBox.tsx
@@ -69,7 +69,7 @@ export class MapBox extends ViewBoxAnnotatableComponent<ViewBoxAnnotatableProps
@observable private _map: google.maps.Map = null as unknown as google.maps.Map;
@observable private selectedPlace: MapMarker | undefined;
@observable private markerMap: { [id: string]: google.maps.Marker } = {};
- @observable private center = defaultCenter;
+ @observable private center = navigator.geolocation ? navigator.geolocation.getCurrentPosition : defaultCenter;
@observable private zoom = 2.5;
@observable private infoWindowOpen = false;
@observable private bounds = new window.google.maps.LatLngBounds();
@@ -107,6 +107,19 @@ export class MapBox extends ViewBoxAnnotatableComponent<ViewBoxAnnotatableProps
private loadHandler = (map: google.maps.Map) => {
this._map = map;
drawingManager.setMap(map);
+ if (navigator.geolocation) {
+ navigator.geolocation.getCurrentPosition(
+ (position: GeolocationPosition) => {
+ const pos = {
+ lat: position.coords.latitude,
+ lng: position.coords.longitude,
+ };
+ this._map.setCenter(pos);
+ }
+ );
+ } else {
+ alert("Your geolocation is not supported by browser.")
+ }
this.fitBounds(map);
}
@@ -268,7 +281,7 @@ export class MapBox extends ViewBoxAnnotatableComponent<ViewBoxAnnotatableProps
<GoogleMap
mapContainerStyle={mapContainerStyle}
zoom={this.zoom}
- center={this.center}
+ // center={this.center}
onLoad={map => this.loadHandler(map)}
options={mapOptions}
>