diff --git a/src/views/map/index.js b/src/views/map/index.js index 0d6201f..3545779 100644 --- a/src/views/map/index.js +++ b/src/views/map/index.js @@ -1,9 +1,10 @@ -import { defer } from 'lodash' +import axios from 'axios' import React, { Component } from 'react' import GoogleMap from 'google-map-react' import { observable, action, toJS } from 'mobx' import { observer } from 'mobx-react' +import Alert from 'react-s-alert' import userLocation from '../../models/user-location.js' import settings from '../../models/settings.js' @@ -17,8 +18,6 @@ import TotalDistance from './total-distance.js' import Autopilot from './autopilot.js' import Pokeball from './pokeball.js' -const isLoading = observable(true) - @observer class Map extends Component { @@ -34,44 +33,36 @@ class Map extends Component { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition( this.handleGeolocationSuccess, - (error) => console.warn(error), + this.handleGeolocationFail, { enableHighAccuracy: true, maximumAge: 0 } ) } } - @action handleGeolocationSuccess({ coords: { latitude, longitude } }) { - userLocation.replace([ latitude, longitude ]) - } - - @action handleDragMap = ({ zoom: newZoom }) => { - if (newZoom !== settings.zoom.get()) { - settings.zoom.set(newZoom) - - // reset zoom if it has been changed by loading `pokemontSpots.kml` - if (isLoading.get() && newZoom === 3) { - defer(() => { - settings.zoom.set(17) - isLoading.set(false) - }) - } + // geolocation API might be down, use http://ipinfo.io + // source: http://stackoverflow.com/a/32338735 + handleGeolocationFail = async (geolocationErr) => { + Alert.warning(` + Error getting your geolocation, using IP location +