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?
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With