F
  • Your shopping cart is empty!
Neighbouring Countries by ISO3166-2 Country Code

GeoDataSource™ Neighbouring Countries Web Service

FREE

GeoDataSource™ Neighbouring Countries Web Service is a REST API enable user to lookup the associated land border countries (the neighbouring countries) based on the input of country code in ISO3166-2 format. It will return the result in either JSON or XML containing the information of the neighbouring countries code and name. Below please find the syntax.

GET https://api.geodatasource.com/neighbouring-countries

Features

  • No database to download, to install or to upgrade in the server side
  • Support HTTP or HTTPS queries up to 500 times per month

Request

Parameter Type Description
key string (required) API key.
country_code char (required) ISO3166-2 Country code.
format string (optional) Return the result in json (default) or xml format.
Valid values: json | xml

Response

Parameter Type Description
country_code string Neighbouring two-character country code based on ISO 3166.
country_name string Neighbouring country name.

Example of response message

{
	"country_code":"CA",
	"country_name":"Canada"
},
{
	"country_code":"MX",
	"country_name":"Mexico"
}

Neighbouring Countries API Sample Code
<?php
$apiKey = 'Enter_API_Key';
$params['format']   = 'json';
$params['country_code']  = 'US';

$query = '';

foreach($params as $key=>$value){
	$query .= '&' . $key . '=' . rawurlencode($value);
}

////////////
//For https request, please make sure you have enabled php_openssl.dll extension.
//
//How to enable https
//- Uncomment ;extension=php_openssl.dll by removing the semicolon in your php.ini, and restart the apache.
//
//In case you have difficulty to modify the php.ini, you can always make the http request instead of https.
////////////
$result = file_get_contents('https://api.geodatasource.com/neighbouring-countries?key=' . $apiKey . $query);

$data = json_decode($result);

print_r($data);
?>
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class GDS {
	public static void main(String[] args) {
		try {

		URL url = new URL("https://api.geodatasource.com/neighbouring-countries?key=Enter_API_Key&format=json&country_code=US");
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		conn.setRequestMethod("GET");
		conn.setRequestProperty("Accept", "application/json");

		if (conn.getResponseCode() != 200) {
			throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
		}

		BufferedReader br = new BufferedReader(new InputStreamReader(
			(conn.getInputStream())));

		String output;

		while ((output = br.readLine()) != null) {
			System.out.println(output);
		}

		conn.disconnect();

	  } catch (MalformedURLException e) {

		e.printStackTrace();

	  } catch (IOException e) {
		e.printStackTrace();
	  }
	}
}
Imports System.Net
Imports System.Security.Cryptography

Partial Public Class _Default
	Inherits System.Web.UI.Page

	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		Dim request As HttpWebRequest = Nothing
		Dim response As Net.HttpWebResponse = Nothing
		Dim stream As IO.Stream = Nothing

		Dim apiKey As String = "Enter_API_Key"
		Dim format As String = "json"
		Dim country_code As String = "US"

		request = Net.WebRequest.Create("https://api.geodatasource.com/neighbouring-countries?key=" & apiKey & _
		"&format=" & System.Web.HttpUtility.UrlEncode(format) & _
		"&country_code=" & System.Web.HttpUtility.UrlEncode(country_code)

		request.Method = "GET"
		response = request.GetResponse()

		Dim reader As System.IO.StreamReader = New IO.StreamReader(response.GetResponseStream())

		Page.Response.Write(reader.ReadToEnd)
	End Sub
End Class
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Net;
using System.Security.Cryptography;

public partial class _Default : System.Web.UI.Page
{

	protected void Page_Load(object sender, System.EventArgs e)
	{
		HttpWebRequest request = null;
		System.Net.HttpWebResponse response = null;
		System.IO.Stream stream = null;

		string apiKey = "Enter_API_Key";
		string format = "json";
		string country_code = "US";

		request = System.Net.WebRequest.Create("https://api.geodatasource.com/neighbouring-countries?key=" + apiKey + "&format=" + System.Web.HttpUtility.UrlEncode(format) + "&country_code=" + System.Web.HttpUtility.UrlEncode(country_code));

		request.Method = "GET";
		response = request.GetResponse();

		System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream());

		Page.Response.Write(reader.ReadToEnd());
	}
}
import httplib
import urllib

p = { 'key': 'Enter_API_Key', 'format': 'json', 'country_code': 'US' }

conn = httplib.HTTPConnection("api.geodatasource.com")
conn.request("GET", "/neighbouring-countries?" + urllib.urlencode(p))
res = conn.getresponse()
print res.read()
$ curl https://api.geodatasource.com/neighbouring-countries?key=Enter_API_Key&format=json&country_code=US
require 'uri'
require 'net/http'

uri = URI.parse("https://api.geodatasource.com/neighbouring-countries?key=Enter_API_Key&format=json&country_code=US")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)

response = http.request(request)
print response.body