2017 © Pedro Peláez
 

library geo-things

Takes various inputs and geo-decodes/encodes, etc.

image

dericcain/geo-things

Takes various inputs and geo-decodes/encodes, etc.

  • Wednesday, December 28, 2016
  • by dericcain
  • Repository
  • 1 Watchers
  • 0 Stars
  • 735 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 16 % Grown

The README.md

Geo Thing

Build Status, (*1)

Description

Ever need to quickly get the address from a set of coordinates? What about getting the coordinates from an address, or even the distance between 2 addresses? This is a very simple package that uses Google's API to perform those very operations. As a default, you do not have to supply an API key but you will be limited with how many API requests you can make. If you are not making a ton of calls, this should be good enough., (*2)

Installation

Use composer to install the package like so:, (*3)

composer require dericcain/geo-things

Usage

It's fairly simple to use the package. You will need to import that package at the top of your PHP file. Once you have done that, you can use the different methods below., (*4)

Get Coordinates from Address

// You will need to declare the namespace
use GeoThing/GeoThing;

$address = '123 Main Street';
$zip = '32119';

$results = GeoThing::getCoordinates($address, $zip);

$results->lat // 33.5075002
$results->lng // -86.8105789
$results->error // The error code from Google if there is one. This attribute will not be here if there is not error.

If there are no results, or there is an error, the object returned will have an error attribute giving the reason for the error. Also, the lat and lng attributes will be set to null., (*5)

Get Address from Coordinates

// You will need to declare the namespace
use GeoThing/GeoThing;

$response = GeoThing::getAddress($lat, $lng);

$response->error // This will only be set if there is an error
$response->street_number // The number only
$response->street_name // The name of the street
$response->city // The full city name
$response->state // The full state name, not the abbreviation
$response->zip // The zip code
$response->formatted_address // The full formated address "277 Bedford Avenue, Brooklyn, NY 11211, USA"

Get Distance between Origin and Destination

// You will need to declare the namespace
use GeoThing/GeoThing;

$response = GeoThing::getDistance($origin, $destination);

$response->error // This will only be set if there is an error
$response->distance // This will be a string like "1.2 mi" (I'll change this soon)
$response->duration // This will also be a string as of right now

Helper Functions

Once the package is installed using Composer, you will have access to some global helper functions. This is good if you want to call the different functions in a view, or somewhere else that is a little more difficult to declare use statements. Here are the helper functions:, (*6)

getAddress($lat, $lng, $apiKey); // $apiKey is optional
getCoordinates($address, $zip, $apiKey); // $apiKey is optional
getDistance($origin, $destination, $apiKey); // $apiKey is optional

Contributing

Please feel free to help with this small project. Let me know if you see a bug, or want to add something. If you do a pull request, make sure that you test your code and all of the tests are passing. This is required before the work will be merged., (*7)

Contact

Give me a shout! - deric.cain@gmail.com - @dericcain, (*8)

TODO

  • [ ] Get distance between two sets of coordinates
  • [ ] Add KM to distance as an option

The Versions

28/12 2016

dev-master

9999999-dev

Takes various inputs and geo-decodes/encodes, etc.

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

by Deric Cain

geolocation geo geocode geoencode

28/12 2016

dev-develop

dev-develop

Takes various inputs and geo-decodes/encodes, etc.

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

by Deric Cain

geolocation geo geocode geoencode

28/12 2016

v1.0

1.0.0.0

Takes various inputs and geo-decodes/encodes, etc.

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

by Deric Cain

geolocation geo geocode geoencode

26/12 2016

v0.9.2

0.9.2.0

Takes various inputs and geo-decodes/encodes, etc.

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

by Deric Cain

geolocation geo geocode geoencode

25/12 2016

v0.9.1

0.9.1.0

Takes various inputs and geo-decodes/encodes, etc.

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

by Deric Cain

geolocation geo geocode geoencode

25/12 2016

v0.9

0.9.0.0

Takes various inputs and geo-decodes/encodes, etc.

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

by Deric Cain

geolocation geo geocode geoencode