16

This Request.JSON http://mootools.net/demos/?demo=Request.JSON using JSON data in a way like this,

var data = {"previews":[
  {"Countrycode":"us", "src":"us.jpg", "description":"desc will be here"},
  {"Countrycode":"uk", "src":"uk.jpg", "description":"desc will be here"},
]};

In the above method we use Countrycode & images by writing name of each image our self.

I'm looking for a method to use Geonames via http://api.geonames.org/export/geonamesData.js?username=orakzai to retrieve Countrycode and CountryFlags via http://www.geonames.org/flags/x/xx.gif where xx is 2 letter ISO country code

Arif
  • 1,222
  • 6
  • 29
  • 60

3 Answers3

25

The flags are returned as GIF files instead of any sort of JSON. You would just use

<img id='myImage' src="http://www.geonames.org/flags/x/??.gif" />

But fill in the ?? with the country code that geonames uses.

You can put the tag in your page somewhere and use some javascript to change the URL to the one you have computed or you can figure the URL on your server and insert it as the HTML page is created.

If you want to do it in javascript, for example, in jQuery you would have something like this to change the URL on an already loaded image tag with id='myImage'

 $("#myImage").attr('src', "http://www.geonames.org/flags/x/" + countryCode + ".gif")
Lee Meador
  • 12,829
  • 2
  • 36
  • 42
  • Its ok for image, but how to get `Countrycode` from http://api.geonames.org/export/geonamesData.js?username=orakzai – Arif Jan 03 '13 at 21:12
  • Its a script, here is the mootools page telling how to load a script: [click here](http://mootools.net/docs/more/Utilities/Assets) and here is jQuery [click here]{http://api.jquery.com/jQuery.getScript/) – Lee Meador Jan 03 '13 at 21:22
  • In case you are using angular it is ng-src with {{countryCode}} – Winnemucca Sep 02 '15 at 19:03
9

Similar service, like geonames.org:

var country_code = 'uk',
  img_uri = 'https://flagpedia.net/data/flags/normal/' + country_code + '.png';
Paramtamtаm
  • 312
  • 5
  • 12
0

Now Geonames flags can be access in following url format:

https://img.geonames.org/flags/x/<2 digit country code in lower case>.gif

Example Url: https://img.geonames.org/flags/x/in.gif

amitshree
  • 2,048
  • 2
  • 23
  • 41