npm i dialectica_geography
var mavenGeo = require('dialectica_geography');
mavenGeography.js is in dist folder minified version
<script src="./your path/mavenGeography.js"></script>
import mavenGeo from "dialectica_geography";
mavenGeo.getListOfNamesCountries();
mavenGeo.getListOfContinents();
mavenGeo.getNameShort("name of country");
mavenGeo.getCapital("name of country");
mavenGeo.getContinent("name of country");
mavenGeo.getDial("name of country");
mavenGeo.getCurrencyCode("name of country");
mavenGeo.getCurrencyName("name of country");
mavenGeo.getTotalArea("name of country");
mavenGeo.getGeonameID("name of country");
For example Greece is the country name for short name 'GR'.
mavenGeo.getCountryFromShortName("short name of country");
Works only on browser environment not in node.js.
mavenGeo.showCountryFlag('element to show', 'short name of country');
//Suppose in html we have the element
<img id='imgId'/>
let element = document.getElementById('imgId');
//or jquery
let element = $('#imgId');
//Country to show flag Greece. Short name of Greece is 'gr'
mavenGeo.showCountryFlag(element, 'gr');
mavenGeo.getGeolocationJsonFromIp("globalObject", ip);
globalObject values are: "window", "node", "local".
When testing from localHost and library is loaded as a script for example
<script src="./dist/mavenGeography.js"></script>
or from browser address bar like this
file://path..../index.html => (script is inside index.html)
we choose globalObject local to avoid Cors errors => response header Origin: null
Above function returns a promise.
let data = await mavenGeo.getGeolocationJsonFromIp("local", "10.0.0.0");
//We can use also .then(function(res) {})
//Then we use the function fetchGeolocationFromJson(data) to get location
let test = mavenGeo.fetchGeolocationFromJson(data);
console.log(test);
//The result is for example "52.37559917665907 4.888916015625"
//First we require https node js library and then passing to function
const https = require('https');
let data = await mavenGeo.getGeolocationJsonFromIp("node", "10.0.0.0", https);
//We can use also .then(function(res) {})
//Then we use the function fetchGeolocationFromJson(data) to get location
let test = mavenGeo.fetchGeolocationFromJson(data);
console.log(test);
//The result is for example "52.37559917665907 4.888916015625"
mavenGeo.getCountryJsonFromIp("globalObject", ip);
globalObject values are: "window", "node", "local".
When testing from localHost and library is loaded as a script for example
<script src="./dist/mavenGeography.js"></script>
or from browser address bar like this
file://..../index.html => (script is inside index.html)
we choose globalObject local to avoid Cors errors => response header Origin: null
Above function returns a promise.
let data = await mavenGeo.getCountryJsonFromIp("local", "10.0.0.0");
//We can use also .then(function(res) {})
//Then we use the function fetchCountryFromJson(data) to get location
let test = mavenGeo.fetchCountryFromJson(data);
console.log(test);
//The result is for example "GR".
//First we require https node js library and then passing to function
const https = require('https');
let data = await mavenGeo.getCountryJsonFromIp("node", "10.0.0.0", https);
//We can use also .then(function(res) {})
//Then we use the function fetchCountryFromJson(data) to get location
let test = mavenGeo.fetchCountryFromJson(data);
console.log(test);
////The result is for example "GR".
mavenGeo.isContinent("name of country", "continent name");
mavenGeo.isApac("name of country");
mavenGeo.isNordigs("name of country");
mavenGeo.isDach("name of country");
mavenGeo.isBenelux("name of country");