Deduplicate nearby station requests
This commit is contained in:
parent
0afe31fba3
commit
77a13639c6
2 changed files with 46 additions and 34 deletions
|
@ -183,8 +183,13 @@ function rebuildSuggestions() {
|
|||
if (nearbyStatus === 'notRequested') {
|
||||
suggestionsArea.appendChild(a('', 'Load nearby stations').event$('click', function (event) {
|
||||
event.preventDefault()
|
||||
var latitude = 0
|
||||
var longitude = 0
|
||||
var watchId = navigator.geolocation.watchPosition(
|
||||
function (data) {
|
||||
if (data.coords.latitude !== latitude || data.coords.longitude !== longitude) {
|
||||
latitude = data.coords.latitude
|
||||
longitude = data.coords.longitude
|
||||
var geoUrl = new URL('https://v6.db.transport.rest/locations/nearby')
|
||||
geoUrl.searchParams.append('latitude', data.coords.latitude.toString())
|
||||
geoUrl.searchParams.append('longitude', data.coords.longitude.toString())
|
||||
|
@ -202,6 +207,7 @@ function rebuildSuggestions() {
|
|||
nearbyStatus = 'unavailable'
|
||||
rebuildSuggestions()
|
||||
})
|
||||
}
|
||||
},
|
||||
function (error) {
|
||||
if (nearbyStations.length === 0) {
|
||||
|
|
|
@ -145,8 +145,13 @@ function rebuildSuggestions() {
|
|||
if (nearbyStatus === 'notRequested') {
|
||||
suggestionsArea.appendChild(a('', 'Load nearby stations').event$('click', function (event) {
|
||||
event.preventDefault()
|
||||
var latitude = 0
|
||||
var longitude = 0
|
||||
var watchId = navigator.geolocation.watchPosition(
|
||||
function (data) {
|
||||
if (data.coords.latitude !== latitude || data.coords.longitude !== longitude) {
|
||||
latitude = data.coords.latitude
|
||||
longitude = data.coords.longitude
|
||||
var geoUrl = new URL('https://v6.db.transport.rest/locations/nearby')
|
||||
geoUrl.searchParams.append('latitude', data.coords.latitude.toString())
|
||||
geoUrl.searchParams.append('longitude', data.coords.longitude.toString())
|
||||
|
@ -164,6 +169,7 @@ function rebuildSuggestions() {
|
|||
nearbyStatus = 'unavailable'
|
||||
rebuildSuggestions()
|
||||
})
|
||||
}
|
||||
},
|
||||
function (error) {
|
||||
if (nearbyStations.length === 0) {
|
||||
|
|
Loading…
Add table
Reference in a new issue