fix api error with undefined cities (somehow)

This commit is contained in:
BuildTools 2021-08-24 22:16:45 -04:00
parent 0a16ba3d9d
commit 17f77c99bd
4 changed files with 9 additions and 5 deletions

View File

@ -54,7 +54,6 @@ function DataManager(pointSearch){
locList.push({lat: latgeo, long:longeo, distance:dist, stationUrl:feature.stationId[i]});
}
}
if (locList.length===0) {
$this.trigger('allinit');
return

View File

@ -55,10 +55,11 @@ function Location() { // onReady, onRefresh, onAllComplete
// ajax the latest observation
$.getJSON(url, function(data) {
if (data['v3-location-point'] != null) {
_observations[0] = json = data['v3-wx-observations-current'];
_observations[0].latitude = loclat;
_observations[0].longitude = loclong;
_observations[0].cityname = data['v3-location-point'].location.city;
_observations[0].cityname = data['v3-location-point'].location.displayName;
$this.trigger('refresh');
// the following block only runs on init
@ -71,14 +72,16 @@ function Location() { // onReady, onRefresh, onAllComplete
that.city = data['v3-location-point'].location.city;
$this.trigger('init');
$this.trigger('init');
}
// set the expiration date/time
_observations[0].xdate = dateFns.addMinutes(json.lastBuildDate, json.ttl);
setTimeout(checkRefresh, getRandom(5000, 10000));
} else {
$this.trigger('init');
}
});
}

View File

@ -1211,9 +1211,11 @@ RADAR < MAIN CITY < CITY 1 < CITY 2
airport='<span class="city airport">AIRPORTS</span>';
for (var location of dataMan.locations) {
if (location.city !== undefined) {
city = location.city;
cities += arrow+'<span class="city" data-woeid="' + location.woeid + '">' + city + '</span>';
}
}
$('#info-slides-header .hscroller').append(cities + arrow + (radar + arrow + airport + arrow + health + cities + arrow).repeat(4));
}

View File

@ -52,7 +52,7 @@ function WeatherManager() {
var queryString = window.location.search;
if (queryString) {
$.getJSON("https://api.weather.com/v3/location/search?query="+queryString.split("?")[1]+"&language=en-US&format=json&apiKey=" + process.env.API_KEY, function(data) {
$.getJSON("https://api.weather.com/v3/location/search?query="+queryString.split("?")[1]+"&language=en-US&format=json&apiKey=" + api_key, function(data) {
dataMan = createDataManager( data.location.latitude[0]+','+data.location.longitude[0] );
mainloc = data.location.city[0]
});