Issues with the Weather API

Issues with the Weather API
0.0 0


Hey guys. So I’m nearly done making the weather APP project, but I’m having a slight issue. My code seems to be only working half the time. Sometimes it shows me the correct location, and other times it shows the fallback in Japan/Shuzenji, but I am not entirely sure why. Even when I look at the URL, I see the correct lat/long of my location IRL, but it still shows Japan sometimes. Anyone know why this might be happening?

My code:

var lat;
var long;

function getLocation() {


function showPosition(position) {
lat = position.coords.latitude;
long = position.coords.longitude;


var xmlhttp = new XMLHttpRequest(),
method = ‘GET’,
url = ‘’ + lat + ‘&lon=’ + long;
console.log(url);, url, true);
xmlhttp.onload = function test() {
var response = JSON.parse(this.responseText);
var weather =[0].main;
var temperature = response.main.temp;
var country =;
var city =;




See the following thread.