library google-geocoding
Google Geocoding SDK
p2/google-geocoding
Google Geocoding SDK
- Tuesday, September 24, 2013
- by phillies2k
- Repository
- 1 Watchers
- 0 Stars
- 13 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 1 Versions
- 0 % Grown
Google Geocoding
v0.9.7, (*1)
Full featured example
<?php
use P2\GoogleGeocoding\Geolocation\Component;
use P2\GoogleGeocoding\Geolocation\Factory;
use P2\GoogleGeocoding\GoogleGeocoding;
// the address to look up
$address = '123 5th Avenue ny';
// create the response factory
// you may specify the class names for each response object
$factory = new Factory(
'Acme\CustomBundle\Document\Geolocation',
'Acme\CustomBundle\Document\Geolocation\AddressComponent',
'Acme\CustomBundle\Document\Geolocation\Geometry',
'Acme\CustomBundle\Document\Geolocation\Viewport',
'Acme\CustomBundle\Document\Geolocation\Location',
);
// initialize the service
$googleGeocoding = new GoogleGeocoding($factory, GoogleGeocoding::FORMAT_JSON);
header('Content-Type: text/plain; charset=utf-8');
echo "\n\nGeocoding (looking up: {$address})\n\n";
// geocoding
$geolocations = $googleGeocoding->findByAddress($address);
foreach ($geolocations as $geolocation) {
echo $geolocation->getFormattedAddress() . "\n";
}
echo "\n\nReverse Geocoding:\n\n";
// reverse geo coding
$geolocations = $googleGeocoding->findByCoordinates(12.128462, 34.924239);
foreach ($geolocations as $geolocation) {
echo "* " . $geolocation->getFormattedAddress() . "\n";
}