Mercurial / geocode by Mercurial
forked from jotafurtado/geocode

Google Geocoding API for Laravel 4
33
0
2
Package Data
Maintainer Username: Mercurial
Maintainer Contact: jotacfurtado@gmail.com (João Carlos)
Package Create Date: 2016-08-03
Package Last Update: 2016-08-03
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-12-19 03:10:50
Package Statistics
Total Downloads: 33
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Google Geocoding API for Laravel

Latest Stable Version Total Downloads License

A simple Laravel service provider for Google Geocoding API.

Installation

This package can be installed via Composer by requiring the jcf/geocode package in your project's composer.json.

{
    "require": {
        "mercurial/geocode": "dev-master"
    }
}

Then run a composer update

php composer.phar update

Laravel 4

After updating composer, add the ServiceProvider to the providers array in app/config/app.php

'Jcf\Geocode\GeocodeServiceProvider',

Add then alias Geocode adding its facade to the aliases array in the same file :

'Geocode' => 'Jcf\Geocode\Facades\Geocode'

Laravel 5

After updating composer, add the ServiceProvider to the providers array in app/config/app.php

Jcf\Geocode\GeocodeServiceProvider::class,

Add then alias Geocode adding its facade to the aliases array in the same file :

'Geocode' => Jcf\Geocode\Facades\Geocode::class,

Usage

You can find data from addresses:

$response = Geocode::make()->address('1 Infinite Loop');

if ($response) {
	echo $response->latitude();
	echo $response->longitude();
	echo $response->formattedAddress();
	echo $response->locationType();
}

// Output
// 37.331741
// -122.0303329
// 1 Infinite Loop, Cupertino, CA 95014, USA
// ROOFTOP

Or from latitude/longitude:

$response = Geocode::make()->latLng(40.7637931,-73.9722014);
if ($response) {
	echo $response->latitude();
	echo $response->longitude();
	echo $response->formattedAddress();
	echo $response->locationType();
}

// Output
// 40.7637931
// -73.9722014
// 767 5th Avenue, New York, NY 10153, USA
// ROOFTOP

If you need other data rather than formatted address, latitude, longitude or location type, you can use the raw() method:

$response = Geocode::make()->latLng(40.7637931,-73.9722014);
if ($response) {
	echo $response->raw()->address_components[8]['types'][0];
	echo $response->raw()->address_components[8]['long_name'];
}

// Output
// postal_code
// 10153

That's it. Pull requests are welcome.