maxmind / GeoIP2-php

PHP API for GeoIP2 webservice client and database reader
https://maxmind.github.io/GeoIP2-php/
Apache License 2.0
2.33k stars 276 forks source link

Documentation on the structure returned by Reader() #1

Closed t3chn0r closed 11 years ago

t3chn0r commented 11 years ago

I'm using this implementation in Symfony2 project and so far so good. Although I would like to get "City", "State", "Country" from an IP address.

I did a test with my IP address and I was able to get the "City" and the "Country" using the following two objects:

$record->city->names['en']
$record->country->names['en']

I haven't figure out how to get the "State" though, I'll be more than glad if you can point me to the documentation (if it exists) on how to get the city name.

Regards

oschwald commented 11 years ago

We provide an array of subdivisions as some countries have multiple levels of ISO regions. However, we do provide a 'mostSpecificSubdivision' attribute that always returns the most specific subdivision available (e.g., a state in the US).

For instance:

$record->mostSpecificSubdivision->name

See http://maxmind.github.io/GeoIP2-php/doc/v0.4.0/class-GeoIp2.Model.City.html for more informatin.

Also, you may want to use:

$record->city->name $record->country->name

These default to English but will use whatever languages you originally provided to the constructor of the database reader or web service client. This is also documented in the API docs that I linked to, but we could probably use a tutorial or more detailed example.

oschwald commented 11 years ago

FYI, I added more detailed examples in the README.md file. Thanks for the report.

t3chn0r commented 11 years ago

Thank you @oschwald, really appreciate it! :+1: