Here I'm trying to get the user's location using geonames api by latitude and longitude. I have a modal form and dropdown which all country is there. What i want to do is when i open the modal it automatically fill the dropdown on what country the user is. But these error is giving me a hard time which is Cross origin error.
NOTE : input_22_15 is the id of the dropdown
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition)
}
else {
console.log("Geolocation is not supported by this browser.");
}
function showPosition() {
$.getJSON('https://api.geonames.org/countryCode?', {
lat: position.coords.latitude,
lng: position.coords.longitude,
username: 'demo',
type: 'JSON'
},
function(result) {
jQuery('#input_22_15').val(result.countryName);
});
}