Reputation: 3428
Is there any way, how to get US state abbr. (CA, VI, ..) from IP?
The library return me only metro code and postal code, is there any lookup table to state convertor? Or how do you extract the state?
Upvotes: 6
Views: 4578
Reputation: 18833
You need to look in the subdivisions
section, which is the generic container for States, Provinces, etc. depending on the country.
If you're using the web API, here are those docs, and this is the relevant chunk from their output example:
"subdivisions": [
{
"confidence": 50,
"geoname_id": 5332921,
"iso_code": "CA",
"names": {
"de": "Kalifornien",
"en": "California",
"es": "California",
"fr": "Californie",
"ja": "カリフォルニア",
"ru": "Калифорния",
"zh-CN": "加州"
}
}
]
The PHP client using a downloaded IP DB has mostSpecificSubdivision
:
print($record->mostSpecificSubdivision->name . "\n"); // 'Minnesota'
print($record->mostSpecificSubdivision->isoCode . "\n"); // 'MN'
Upvotes: 12