0

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);
});
}

enter image description here

Community
  • 1
  • 1
  • Does this help: https://stackoverflow.com/questions/6849802/jquery-getjson-works-locally-but-not-cross-domain? – umop apisdn Jul 11 '19 at 02:23
  • @umopapisdn will try this –  Jul 11 '19 at 02:26
  • CORS issues can be resolved either by a) changes to the server or b) using YOUR server make requests to the other server. Anything else is a hack or unreliable – Jaromanda X Jul 11 '19 at 02:48

0 Answers0