Print all supported countries and sub-regions

1,589 views
Skip to first unread message

Diogo Ribeiro

unread,
Oct 25, 2015, 8:26:33 AM10/25/15
to libphonenumber-discuss
I want to use libphonenumber to print all supported countries and sub-regions.

I know I can list all supported regions using in java:


PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
for (String s : phoneUtil.getSupportedRegions()) {
 
System.out.println(s);
}

But how can I access all sub-regions? The following code will print "New York, NY"


String nyNumber = "+1 212-565-0000";
PhoneNumber numberProto = phoneUtil.parse(nyNumber, "CH");
System.out.println(geoCoder.getDescriptionForNumber(numberProto, Locale.ENGLISH, "US"));

Thanks.


(Originally posted in stackoverflow http://stackoverflow.com/questions/33327395/print-all-supported-countries-and-sub-regions)


Andy Staudacher

unread,
Oct 26, 2015, 4:30:32 AM10/26/15
to libphonenum...@googlegroups.com
Can you provide more context on what you intend to do with this list / set of supported sub-regions? What's the higher-level goal?

Independently of phone numbers or libphonenumber, if you want to get a list/set of subdivisions of a each region (country), you could use the ISO 3166-2 subdivision data.

If you're interested in the coverage of libphonenumber, it depends on what your definition of "supported" is. Are you specifically interested in the geocoder's coverage? Then you might rather want to use the geocoder's data files directly (the mapping of prefix to some human-readable locality/sub-region name). It was never designed for machine processing / machine readable / stable identifiers for locations though.

--
You received this message because you are subscribed to the Google Groups "libphonenumber-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libphonenumber-di...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Diogo Ribeiro

unread,
Oct 26, 2015, 5:50:49 AM10/26/15
to libphonenum...@googlegroups.com
Thanks for your reply Andy.

Yes I'm specifically interested in geocoder's coverage.

I'm developing an app which receives a phone number and must return the region coordinates. As it must work offline I need to know all coverage provided by geocoder to create a file with something like: US;NY;latitude;longitude.

The data files you're mentioning are those in: https://github.com/googlei18n/libphonenumber/tree/master/resources/geocoding?

--
You received this message because you are subscribed to a topic in the Google Groups "libphonenumber-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/libphonenumber-discuss/RKYIAGCQNgk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to libphonenumber-di...@googlegroups.com.

Andy Staudacher

unread,
Oct 26, 2015, 7:06:09 AM10/26/15
to libphonenum...@googlegroups.com
On Mon, Oct 26, 2015 at 10:50 AM, Diogo Ribeiro <diogota...@gmail.com> wrote:
Thanks for your reply Andy.

Yes I'm specifically interested in geocoder's coverage.

I'm developing an app which receives a phone number and must return the region coordinates. As it must work offline I need to know all coverage provided by geocoder to create a file with something like: US;NY;latitude;longitude.

The data files you're mentioning are those in: https://github.com/googlei18n/libphonenumber/tree/master/resources/geocoding?

Indeed. The files are organized by the language/locale (e.g. "en/") of the display name of the location. I.e. you should take the union of all files to map from a prefix to a location.
In terms of matching, longest prefix match wins.
Obviously you don't get lat/long from these files. You'll have to geocode / look up coordinates (or polygons) by these names from some other data source, such as https://developers.google.com/maps/documentation/geocoding/intro .

Diogo Ribeiro

unread,
Oct 26, 2015, 7:17:45 AM10/26/15
to libphonenum...@googlegroups.com
Thanks again for all the help!
Reply all
Reply to author
Forward
0 new messages