Package Data | |
---|---|
Maintainer Username: | badebiyi |
Maintainer Contact: | bodunde.adebiyi@andela.com (Adebiyi Bodunde) |
Package Create Date: | 2016-10-09 |
Package Last Update: | 2019-07-20 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-02-09 15:01:08 |
Package Statistics | |
---|---|
Total Downloads: | 7,476 |
Monthly Downloads: | 27 |
Daily Downloads: | 1 |
Total Stars: | 24 |
Total Watchers: | 4 |
Total Forks: | 9 |
Total Open Issues: | 2 |
A Laravel Package that interfaces with the google maps API to help convert a plain address to longitude and latitude coordinates and vice-versa. It can also calculate the distance (in kilometers or miles) between two locations using their coordinates.
composer.json
file and run composer update
or run composer require bodunde/geocoder
or you can do it oldschool and just clone the repo and include it in your application.config
directory in your laravel application and locate the app.php
fileBodunde\GoogleGeocoder\GeocoderServiceProvider::class
php artisan vendor:publish
google_api_key
in geocoder.php
file located in the config directory
Voila!!! You are done<?php
namespace Your\Namespace;
use Bodunde\GoogleGeocoder\Geocoder;
...
...
// using dependency injection
public function index(Geocoder $geocoder)
{
// get coordinates
$coordinates = $geocoder->getCoordinates('55 Moleye Street, Yaba');
// get address via reverse geocoding
$addressCoordinates = [
"lat" => 6.5349646,
"lng" => 3.3892894
];
$address = $geocoder->getAddress($addressCoordinates);
// get distance between two locations
$location1 = [
"lat" => 6.5349646,
"lng" => 3.3892894
];
$location2 = [
"lat" => 6.601838,
"lng" => 3.3514863
];
$distance = $geocoder->getDistanceBetween($location1, $location2);
/** geocoder can also be instantiated normally without DI */
//e.g $geocoder = new Geocoder;
}
In the package root run phpunit