Skip to content

A wrapper around the Google Geocoding API to get different details such as latitude, longitude, country, city, district, postcode, town and street number regarding some specific address.

License

Notifications You must be signed in to change notification settings

ckdarby/php-geocode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#PHP Geocode Build Status Code Coverage Latest Stable Version License

A wrapper around the Google Geocoding API to get different details regarding an address such as

  • Latitude/longitude
  • Country
  • City
  • District
  • Postcode
  • Town
  • Street number

##Requirement PHP >= 5.3.0 and curl enabled server.

##Installation You can install the library using the following ways ##Composer The recommended installation method is through Composer, a dependency manager for PHP. Just add kamranahmedse/php-geocode to your project's composer.json file:

{
    "require": {
        "kamranahmedse/php-geocode": "*"
    }
}

and then run composer install. For further details you can find the package at Packagist.

##Manual way Or you can install the package manually by:

  • Copy src/php-geocode.php to your codebase, perhaps to the vendor directory.
  • Add the Geocode class to your autoloader or require the file directly.

##Getting Started I'm going to use the following address to explain the use of library i.e.

1600 Amphitheatre Parkway, Mountain View, CA

Firstly, you have to instantiate the Geocode class and pass the address, so your code will look like

// Introduce the class into your scope
use kamranahmedse\Geocode;

$address = "1600 Amphitheatre Parkway, Mountain View, CA";

$geocode = new Geocode( $address );
// Optionally you can pass a second parameter set to true if you want to use https instead of http
// $geocode = new Geocode( $address, true );

// Note: All the functions below accept a parameter as a default value that will be return if the reuqired value isn't found
$geocode->getAddress( 'default value' ); 
$geocode->getLatitude(); // returns the latitude of the address
$geocode->getLongitude(); // returns the longitude of the address
$geocode->getCountry(); // returns the country of the address
$geocode->getLocality(); // returns the locality/city of the address
$geocode->getDistrict(); // returns the district of the address
$geocode->getPostcode(); // returns the postal code of the address
$geocode->getTown(); // returns the town of the address
$geocode->getStreetNumber(); // returns the street number of the address

##Feedback I'd love to hear what you have to say. Please open an issue for any feature requests that you may want or the bugs that you notice. Also you can contact me at [email protected] or you can also find me at twitter @kamranahmed_se

About

A wrapper around the Google Geocoding API to get different details such as latitude, longitude, country, city, district, postcode, town and street number regarding some specific address.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages