I\'m using the Google Visualization Geochart API to create a map of a country\'s regions. I provide the ISO 3266-2 Country subdivision code and get the correct results. Howe
From my experience there are several problems with ISO 3166-2 apart from the codes being unknown to most mortals.
There seems to be no location where a machine-processable up to date version can be found freely available.
The assignments keep changing except in the most stable (typically federal) countries like US and Canada. There are machine-processable but out of date versions freely available.
The country names that people use are not always the official (somewhat long names).
The region names in some countries do not correspond to local views of what the regions truly are (far worse at the subregion level).
The (sub)region names are a weird mixture of English or the local language.
For those applications still ASCII-focussed there are not official ASCII fallbacks of the Unicode names.
I do not have an algorithmic solution to this but my pragmatic solution to the country-to-code issue is to have a long look-up table to handle the usual variants of country names and then a reverse lookup from code into an acceptable "canonical" form. Because of #6 in my case I ensure that the canonical forms are ASCII. I do a similar task for languages in ISO 639-1 and -3.
Making such a list for all regions in ISO 3166-2 is a VERY long task - at present I am focussing on the OECD, BRIC and EU countries as that gets one a long way.
This is a quick proof of concept that works, I'm looking at something similar and was hoping to get the name automatically but I'm not sure if that's possible quite yet but this at least allows manual population of the tooltip text.
The key factors are to create your table with the required columns and then apply a PatternFormat to get the tooltip as you want it then create a data view with only those columns that are required for the data binding.
function drawVisualization() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Country');
data.addColumn('number', 'Value');
data.addColumn('string', 'Display');
data.addRows([
['Germany', 200, 'Germany'],
['United States', 300, 'USA'],
['Brazil', 400, 'Brasil'],
['Canada', 500, 'Canada'],
['France', 600, 'France'],
['RU', 700, 'Russia']
]);
var geochart = new google.visualization.GeoChart(
document.getElementById('visualization'));
var formatter = new google.visualization.PatternFormat('{1}');
formatter.format(data, [0, 2]);
var view = new google.visualization.DataView(data);
view.setColumns([0, 1]);
geochart.draw(view, {width: 556, height: 347});
}