Coder Social home page Coder Social logo

geocode's Introduction

Google Geocoding API for Laravel 4

Fork which requires new version guzzle

Latest Stable Version Total Downloads License

A simple Laravel 4 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": {
        "dmitrymomot/geocode": "1.0.*"
    }
}

Then run a composer update

php composer.phar update

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'

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.

geocode's People

Contributors

jotafurtado avatar dmitrymomot avatar dave-miller avatar

Stargazers

Hugo Fabriicio avatar Breno Douglas  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.