salmanzafar / laravel-geocode
A Laravel Library to find Lat and Long of a given Specific Address
Installs: 3 487
Dependents: 0
Suggesters: 0
Security: 0
Stars: 15
Watchers: 3
Forks: 4
Open Issues: 0
pkg:composer/salmanzafar/laravel-geocode
Requires
- php: ^7.0 || ^7.1 || ^7.2 || ^7.3 || ^7.4
- laravel/framework: ^5.5 || ^6.0 || ^7.0 || ^8.0
Requires (Dev)
- ext-curl: *
README
Laravel Package to get Lat and Long from Specific Address.
Table of contents
Installation
composer require salmanzafar/laravel-geocode
Configuration
Publish the configuration file
php artisan vendor:publish --provider="Salman\GeoCode\GeoCodeServiceProvider"
Config/geocode.php
'API_KEY' => env('GOOGLE_GEOCODE_API_KEY', ''),
Enable the package (Optional)
This package implements Laravel auto-discovery feature
Usage
You need a Google map geocode api key in order to use this
Finding Coordinates
use Salman\GeoCode\Services\GeoCode; public function lookForPoints() { $address = "1600 Amphitheatre Parkway,Mountain View"; $getPoints = new GeoCode(); return $getPoints->getLatAndLong($address); }
Finding Coordinates using Facade
use GeoCode; public function lookForPoints() { $address = "1600 Amphitheatre Parkway,Mountain View"; return GeoCode::getLatAndLong($address); }
Finding Coordinates using Helper Function
public function lookForPoints() { $address = "1600 Amphitheatre Parkway,Mountain View"; return findAddressCoordinates($address); }
Response
It will return a Laravel collection as response
{
"address_components": [
{
"long_name": "1600",
"short_name": "1600",
"types": [
"street_number"
]
},
{
"long_name": "Amphitheatre Parkway",
"short_name": "Amphitheatre Pkwy",
"types": [
"route"
]
},
{
"long_name": "Mountain View",
"short_name": "Mountain View",
"types": [
"locality",
"political"
]
},
{
"long_name": "Santa Clara County",
"short_name": "Santa Clara County",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "California",
"short_name": "CA",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United States",
"short_name": "US",
"types": [
"country",
"political"
]
},
{
"long_name": "94043",
"short_name": "94043",
"types": [
"postal_code"
]
}
],
"formatted_address": "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
"geometry": {
"location": {
"lat": 37.4220579,
"lng": -122.0840897
},
"location_type": "ROOFTOP",
"viewport": {
"northeast": {
"lat": 37.42340688029149,
"lng": -122.0827407197085
},
"southwest": {
"lat": 37.4207089197085,
"lng": -122.0854386802915
}
}
},
"place_id": "ChIJtYuu0V25j4ARwu5e4wwRYgE",
"plus_code": {
"compound_code": "CWC8+R9 Mountain View, CA, USA",
"global_code": "849VCWC8+R9"
},
"types": [
"street_address"
]
}