US state by area code and vice versa

341 views
Skip to first unread message

Juri Bogdanov

unread,
Jan 11, 2017, 5:19:07 AM1/11/17
to libphonenumber-discuss
Is there possibility to get US State by US phone number or by area code?
Something relevant to:

Juri Bogdanov

unread,
Jan 11, 2017, 12:48:16 PM1/11/17
to libphonenumber-discuss

David Cantrell

unread,
Jan 12, 2017, 9:41:38 AM1/12/17
to 'Juri Bogdanov' via libphonenumber-discuss
The data is in resources/geocoding/en/1.txt. I presume that it's exposed
somewhere by the library but I don't know where (I'm only here because I
use the data in my related project). You'll have to do a certain amount
of parsing of the place names to get consistent results, and note that
you'll have to check that a number is a *US* number, because eg
1418|Quebec and 1418226|Saint-Georges, QC are in there, which you may
not want. If you *do* want to extract data for non-US NANP countries
then you need to be aware that it's not complete. For example, the data
for Jamaica consists entirely of ...

1876957|Negril

and there's no data at all for Montserrat (1664)

(would the maintainers like a patch which at least provides the basics
like 1664|Montserrat for the missing countries?)

Oh, and when extracting the state from a number don't just assume "it's
the bit after the comma" because there is at least one entry with more
than one comma ...

1718250|Downtown Brooklyn, Brooklyn, NY

--
David Cantrell | Godless Liberal Elitist

I apologize if I offended you personally,
I intended to do it professionally.
-- Steve Champeon, on the nanog list

Aravind Penmetsa

unread,
Jan 16, 2017, 11:05:28 PM1/16/17
to libphonenum...@googlegroups.com

Hi Juri,


Thank you for using libphonenumber and mailing us on this.


You can make use of APIs in PhoneNumberOfflineGeocoder to know the geocoding values.

Sample code is present in libphonenumber GitHub page.


For US, the geocoding details are in “area name, state name” format.

Demo link: https://libphonenumber.appspot.com/phonenumberparser?number=%2B12012000000


As mentioned by David the format is not consistent for few prefixes.


Thanks & Regards,

Aravind




--
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-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Thanks & Regards,
Aravind

Lara Rennie

unread,
Jan 17, 2017, 4:41:47 AM1/17/17
to libphonenum...@googlegroups.com
Actually we have the data for Montserrat; this is not in this file because it is a "region" all by itself so it's in the general XML file. If you use getRegionCodeForNumber and provide a number with a Montserrat area code, you will get MS returned. If anyone had any more *detailed* data for Montserrat (down to e.g. town level, if such a thing makes any sense for an island so small), we would include it in the geocoding data file.

To unsubscribe from this group and stop receiving emails from it, send an email to libphonenumber-discuss+unsubscri...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Thanks & Regards,
Aravind
Reply all
Reply to author
Forward
0 new messages