Download the PHP package thorazine/location without Composer
On this page you can find all versions of the php package thorazine/location. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download thorazine/location
More information about thorazine/location
Files in thorazine/location
Package location
Short Description A location reverser for Laravel with Google API
License MIT
Informations about the package location
Geo data to Geolocation
Get a complete standardized location php array or object from coordinates, address, postal code or IP. Through the Location Facade you can request the Google and IpInfo API to return the address of a visitor on your website. This script works out of the box, no need for any keys or registrations.
What you should keep in mind
This script uses the Google geodata and maps API to request information. Especially with the IP API there is margin for error. The Google API is quite accurate. However, please don't use this data as fact but rather as indication.
How to make it work
Run:
That's it
If you are on Laravel < 5.5
You can't use this version. Please go to the pre55 branch
Other optional stuff
Get the configuration:
If you have a Google key add a line to your .env file:
This script used to work out of the box without a key, but it doesn't anymore. Thanks Google. You can request one here Do make sure it has sufficiant rights.
These (quick examples):
Will all result in:
To return it as object set the function to true:
Limit results by country
To limit the search results to only be included when from a set of predefined countries, use the function. It accepts iso notation country names as defined by "ISO 3166-1 alpha-2".
Extended example:
The result is the default template and starts out as empty and gets filled throughout the call. So if no data is available the result for that entry will be "". After every call the script resets to it's initial template.
Chainable functions and their variables
Functions | Values | Validation | Type |
---|---|---|---|
countries() | iso's | required | array |
coordinatesToAddress() | latitude | required | float |
longitude | required | float | |
addressToCoordinates() | country | recommended | string |
region | string | ||
city | required | string | |
street | recommended | string | |
street_number | recommended | string | |
postalcodeToCoordinates() | postal_code | required | string |
street_number | recommended | string | |
get() | true/false | boolean | boolean |
Other functions
Functions | Values | Result |
---|---|---|
error() | none | Returns any error if there is one |
response() | none | Returns the raw response from the Google API |
Debug
With the try catch you can already see what you need. But besides this there is also a cached result of the raw response from the google API. Please note that this is not the case with the ip request.