https://github.com/simonsmith/google-map-geocode
PHP class that allows retrieval of address data from the Google Maps API
https://github.com/simonsmith/google-map-geocode
Last synced: 7 months ago
JSON representation
PHP class that allows retrieval of address data from the Google Maps API
- Host: GitHub
- URL: https://github.com/simonsmith/google-map-geocode
- Owner: simonsmith
- Created: 2012-04-06T19:07:27.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2012-04-06T19:25:21.000Z (about 14 years ago)
- Last Synced: 2024-10-18T08:36:36.206Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 85.9 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Google Map Geocode
Returns an object of address data from [the Google maps API](https://developers.google.com/maps/documentation/geocoding/).
## Usage
The class provides two methods to retrieve addresses:
```php
$geo = new Google_Map_Geocode();
$geo->get_address('London, UK');
$geo->get_latlong('51.535879,0.696966');
?>
```
### Default URL parameters
The default parameters are:
```php
array(
'query' => 'address' /* or */ 'latlng' // This is added depending on which method is called
'type' => 'address',
'sensor' => 'false'
);
?>
```
The following URL is substituted with the params using [vsprintf](http://php.net/manual/en/function.vsprintf.php):
http://maps.googleapis.com/maps/api/geocode/json?%2$s=%1$s&sensor=%3$s
### Adding your own parameters
Instantiate the object with the new url as an argument. In this example the default region that is searched will be set to the UK:
```php
$geo = new Google_Map_Geocode('http://maps.googleapis.com/maps/api/geocode/json?%2$s=%1$s&sensor=%3$s®ion=%4$s');
$geo->get_address('London', array(
'region' => 'uk'
));
?>
```
## Notes
Please respect the [Google Maps API usage agreement](https://developers.google.com/maps/terms#section_10_12)
I intend to improve the way additional URL parameters are added at some point, but if you have any suggestions please make a pull request or open an issue.
Cheers