diff --git a/src/components/Navigation/index.jsx b/src/components/Navigation/index.jsx index fcc506f7..fec3addd 100644 --- a/src/components/Navigation/index.jsx +++ b/src/components/Navigation/index.jsx @@ -7,9 +7,9 @@ import { withStyles, Typography, Button } from '@material-ui/core'; import { Clear } from '@material-ui/icons'; import dayjs from 'dayjs'; -import { athena as Athena, devices as Devices } from '@commaai/api'; +import { devices as Devices } from '@commaai/api'; import { primeNav, analyticsEvent } from '../../actions'; -import { DEFAULT_LOCATION, MAPBOX_STYLE, MAPBOX_TOKEN, networkPositioning, reverseLookup } from '../../utils/geocode'; +import { DEFAULT_LOCATION, MAPBOX_STYLE, MAPBOX_TOKEN, reverseLookup } from '../../utils/geocode'; import Colors from '../../colors'; import { PinCarIcon } from '../../icons'; import { timeFromNow } from '../../utils'; @@ -135,8 +135,6 @@ const initialState = { hasFocus: false, carLastLocation: null, carLastLocationTime: null, - carNetworkLocation: null, - carNetworkLocationAccuracy: null, geoLocateCoords: null, searchSelect: null, searchLooking: false, @@ -178,7 +176,6 @@ class Navigation extends Component { this.itemLngLat = this.itemLngLat.bind(this); this.viewportChange = this.viewportChange.bind(this); this.getDeviceLastLocation = this.getDeviceLastLocation.bind(this); - this.getDeviceNetworkLocation = this.getDeviceNetworkLocation.bind(this); this.getCarLocation = this.getCarLocation.bind(this); this.carLocationCircle = this.carLocationCircle.bind(this); this.clearSearchSelect = this.clearSearchSelect.bind(this); @@ -193,9 +190,9 @@ class Navigation extends Component { componentDidUpdate(prevProps, prevState) { const { dongleId, device } = this.props; - const { geoLocateCoords, search, carLastLocation, carNetworkLocation, searchSelect } = this.state; + const { geoLocateCoords, search, carLastLocation, searchSelect } = this.state; - if ((carLastLocation && !prevState.carLastLocation) || (carNetworkLocation && !prevState.carNetworkLocation) + if ((carLastLocation && !prevState.carLastLocation) || (geoLocateCoords && !prevState.geoLocateCoords) || (searchSelect && prevState.searchSelect !== searchSelect) || (search && prevState.search !== search)) { this.flyToMarkers(); @@ -214,7 +211,7 @@ class Navigation extends Component { if (!prevState.hasFocus && this.state.hasFocus) { this.props.dispatch(analyticsEvent('nav_focus', { - has_car_location: Boolean(carLastLocation || carNetworkLocation), + has_car_location: Boolean(carLastLocation), })); } @@ -239,7 +236,6 @@ class Navigation extends Component { updateDevice() { this.getDeviceLastLocation(); - this.getDeviceNetworkLocation(); } async getDeviceLastLocation() { @@ -263,46 +259,9 @@ class Navigation extends Component { } } - async getDeviceNetworkLocation() { - const { dongleId } = this.props; - - const payload = { - method: 'getNetworks', - jsonrpc: '2.0', - id: 0, - }; - try { - let resp = await Athena.postJsonRpcPayload(dongleId, payload); - if (!resp.result || Object.keys(resp.result).length === 0 || !this.mounted || dongleId !== this.props.dongleId) { - return; - } - resp = await networkPositioning(resp.result); - if (resp && this.mounted && dongleId === this.props.dongleId) { - this.setState({ - carNetworkLocation: [resp.lng, resp.lat], - carNetworkLocationAccuracy: resp.accuracy, - }, this.flyToMarkers); - } - } catch (err) { - if (this.mounted && dongleId === this.props.dongleId - && (!err.message || err.message.indexOf('{"error": "Device not registered"}') === -1)) { - console.error(err); - Sentry.captureException(err, { fingerprint: 'nav_fetch_network_location' }); - } - } - } - getCarLocation() { - const { carLastLocation, carLastLocationTime, carNetworkLocation, carNetworkLocationAccuracy } = this.state; + const { carLastLocation, carLastLocationTime } = this.state; - if (carNetworkLocation && carNetworkLocationAccuracy <= 10000 - && (carNetworkLocationAccuracy <= 100 || !carLastLocation)) { - return { - location: carNetworkLocation, - accuracy: carNetworkLocationAccuracy, - time: Date.now(), - }; - } if (carLastLocation) { return { location: carLastLocation, diff --git a/src/utils/geocode.js b/src/utils/geocode.js index fd313782..2c0b6e2c 100644 --- a/src/utils/geocode.js +++ b/src/utils/geocode.js @@ -10,7 +10,6 @@ export const DEFAULT_LOCATION = { export const MAPBOX_STYLE = 'mapbox://styles/commaai/cjj4yzqk201c52ss60ebmow0w'; export const MAPBOX_TOKEN = 'pk.eyJ1IjoiY29tbWFhaSIsImEiOiJjangyYXV0c20wMGU2NDluMWR4amUydGl5In0.6Vb11S6tdX6Arpj6trRE_g'; -const HERE_API_KEY = 'O0atgmTwzKnwYJL2hk5N5qqG2R9y78f5GdHlvr_mtiw'; const geocodingClient = mbxGeocoding({ accessToken: MAPBOX_TOKEN }); @@ -194,16 +193,3 @@ export async function reverseLookup(coords, navFormat = false) { return null; } -export async function networkPositioning(req) { - const resp = await fetch(`https://positioning.hereapi.com/v2/locate?apiKey=${HERE_API_KEY}&fallback=any,singleWifi`, { - method: 'POST', - headers: new Headers({ 'Content-Type': 'application/json' }), - body: JSON.stringify(req), - }); - if (!resp.ok) { - console.error(resp); - return null; - } - const json = await resp.json(); - return json.location; -} diff --git a/src/utils/geocode.test.js b/src/utils/geocode.test.js index 6d2d32d8..95327aba 100644 --- a/src/utils/geocode.test.js +++ b/src/utils/geocode.test.js @@ -34,7 +34,7 @@ describe('reverseLookup', () => { // place: 'White House Lawn', // }); expect(await reverseLookup([-0.106640, 51.514209], true)).toEqual({ - details: 'London, EC4A 2BB, United Kingdom', + details: 'London, EC4A 2BH, United Kingdom', place: 'Fleet St', }); expect(await reverseLookup([-2.076843, 51.894799], true)).toEqual({