This is my request
request = 'http://ws.geonames.org/findNearbyPlaceNameJSON?lat=' + puntlocatielat + '&lng=' + puntlocatielng + '&callback=getLocation';
This is my callback function
function getLocation(jData) {
if (jData != null) {
var place = jData.geonames[0];
puntstad = place["name"];
puntprovincie = place["adminName1"];
puntland = place["countryName"];
puntlandcode = place["countryCode"];
titel = puntstad+", "+puntprovincie+", "+puntland;
//puntstad = "";
//puntprovincie = jData.adminName1;
//puntland = jData.countryName;
//puntlandcode = jData.countryCode;
//titel = jData.adminName1+", "+jData.countryName;
if (document.getElementById('fadres').value == "") {
puntadres = titel;
}
else {
puntadres = document.getElementById('fadres').value;
}
}
else {
puntstad = "";
puntprovincie = "";
puntland = "";
puntlandcode = "";
titel = "Latitude: "+puntlocatielat+" "+"Longitude: "+puntlocatielng;
}
This is the script error; the lat and lng are in this request in liya; the error is that 'name' is empty or no object.
I guess your problem has to do with the variable 'place' being null if no result could be found. Why don't you put another if after the assignment of 'place' checking whether it is not null?