├── .github └── FUNDING.yml ├── .gitignore ├── LICENSE ├── Readme.md ├── composer.json └── src ├── Facades └── GeoCode.php ├── GeoCodeServiceProvider.php ├── Helper └── Helpers.php ├── Services ├── GeoCode.php └── GeoCodeService.php └── config └── geocode.php /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # patreon: salmanzafar949 2 | # custom: ['https://www.buymeacoffee.com/salmanzafar949'] 3 | custom: ['paypal.me/salmanzafar949'] 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | node_modules/ 3 | npm-debug.log 4 | yarn-error.log 5 | .idea 6 | .vscode 7 | # Laravel 4 specific 8 | bootstrap/compiled.php 9 | app/storage/ 10 | 11 | # Laravel 5 & Lumen specific 12 | public/storage 13 | public/hot 14 | 15 | # Laravel 5 & Lumen specific with changed public path 16 | public_html/storage 17 | public_html/hot 18 | 19 | storage/*.key 20 | .env 21 | Homestead.yaml 22 | Homestead.json 23 | /.vagrant 24 | .phpunit.result.cache 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 salman zafar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # laravel-geocode 2 | 3 | ![stars](https://img.shields.io/github/stars/salmanzafar949/laravel-geocode) 4 | ![issues](https://img.shields.io/github/issues/salmanzafar949/laravel-geocode) 5 | ![forks](https://img.shields.io/github/forks/salmanzafar949/laravel-geocode) 6 | ![license](https://img.shields.io/github/license/salmanzafar949/laravel-geocode) 7 | [![Total Downloads](https://img.shields.io/packagist/dt/salmanzafar/laravel-geocode?style=flat-square)](https://packagist.org/packages/salmanzafar/laravel-geocode) 8 | 9 | Laravel Package to get Lat and Long from Specific Address. 10 | 11 | ## Table of contents 12 | * [Installation](#installation) 13 | * [Configuration](#configuration) 14 | * [Usage](#usage) 15 | 16 | # Installation 17 | 18 | ```bash 19 | composer require salmanzafar/laravel-geocode 20 | ``` 21 | 22 | ## Configuration 23 | Publish the configuration file 24 | 25 | ```bash 26 | php artisan vendor:publish --provider="Salman\GeoCode\GeoCodeServiceProvider" 27 | ``` 28 | ## Config/geocode.php 29 | ``` 30 | 'API_KEY' => env('GOOGLE_GEOCODE_API_KEY', ''), 31 | ``` 32 | ## Enable the package (Optional) 33 | This package implements Laravel auto-discovery feature 34 | 35 | 36 | ## Usage 37 | 38 | You need a Google map geocode api key in order to use this 39 | 40 | 41 | #### Finding Coordinates 42 | 43 | ```php 44 | use Salman\GeoCode\Services\GeoCode; 45 | 46 | public function lookForPoints() 47 | { 48 | $address = "1600 Amphitheatre Parkway,Mountain View"; 49 | $getPoints = new GeoCode(); 50 | return $getPoints->getLatAndLong($address); 51 | } 52 | ``` 53 | #### Finding Coordinates using Facade 54 | ```php 55 | use GeoCode; 56 | 57 | public function lookForPoints() 58 | { 59 | $address = "1600 Amphitheatre Parkway,Mountain View"; 60 | return GeoCode::getLatAndLong($address); 61 | } 62 | ``` 63 | 64 | #### Finding Coordinates using Helper Function 65 | ```php 66 | public function lookForPoints() 67 | { 68 | $address = "1600 Amphitheatre Parkway,Mountain View"; 69 | return findAddressCoordinates($address); 70 | } 71 | ``` 72 | 73 | #### Response 74 | ##### It will return a Laravel collection as response 75 | 76 | ```json 77 | { 78 | "address_components": [ 79 | { 80 | "long_name": "1600", 81 | "short_name": "1600", 82 | "types": [ 83 | "street_number" 84 | ] 85 | }, 86 | { 87 | "long_name": "Amphitheatre Parkway", 88 | "short_name": "Amphitheatre Pkwy", 89 | "types": [ 90 | "route" 91 | ] 92 | }, 93 | { 94 | "long_name": "Mountain View", 95 | "short_name": "Mountain View", 96 | "types": [ 97 | "locality", 98 | "political" 99 | ] 100 | }, 101 | { 102 | "long_name": "Santa Clara County", 103 | "short_name": "Santa Clara County", 104 | "types": [ 105 | "administrative_area_level_2", 106 | "political" 107 | ] 108 | }, 109 | { 110 | "long_name": "California", 111 | "short_name": "CA", 112 | "types": [ 113 | "administrative_area_level_1", 114 | "political" 115 | ] 116 | }, 117 | { 118 | "long_name": "United States", 119 | "short_name": "US", 120 | "types": [ 121 | "country", 122 | "political" 123 | ] 124 | }, 125 | { 126 | "long_name": "94043", 127 | "short_name": "94043", 128 | "types": [ 129 | "postal_code" 130 | ] 131 | } 132 | ], 133 | "formatted_address": "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA", 134 | "geometry": { 135 | "location": { 136 | "lat": 37.4220579, 137 | "lng": -122.0840897 138 | }, 139 | "location_type": "ROOFTOP", 140 | "viewport": { 141 | "northeast": { 142 | "lat": 37.42340688029149, 143 | "lng": -122.0827407197085 144 | }, 145 | "southwest": { 146 | "lat": 37.4207089197085, 147 | "lng": -122.0854386802915 148 | } 149 | } 150 | }, 151 | "place_id": "ChIJtYuu0V25j4ARwu5e4wwRYgE", 152 | "plus_code": { 153 | "compound_code": "CWC8+R9 Mountain View, CA, USA", 154 | "global_code": "849VCWC8+R9" 155 | }, 156 | "types": [ 157 | "street_address" 158 | ] 159 | } 160 | ``` 161 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "salmanzafar/laravel-geocode", 3 | "description": "A Laravel Library to find Lat and Long of a given Specific Address", 4 | "type": "library", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Salman Zafar", 9 | "email": "salmanzafar949@gmail.com" 10 | } 11 | ], 12 | "keywords": [ 13 | "laravel", 14 | "laravel5", 15 | "laravel6", 16 | "laravel7", 17 | "laravel8", 18 | "geocode-laravel", 19 | "laravel-geocode", 20 | "google maps laravel geocode", 21 | "google maps laravel geocoder", 22 | "php", 23 | "php 7.0", 24 | "php 7.1", 25 | "php 7.2", 26 | "php 7.3", 27 | "php 7.4" 28 | ], 29 | "minimum-stability": "dev", 30 | "require": { 31 | "php": "^7.0 || ^7.1 || ^7.2 || ^7.3 || ^7.4", 32 | "laravel/framework": "^5.5 || ^6.0 || ^7.0 || ^8.0" 33 | }, 34 | "require-dev": { 35 | "ext-curl": "*" 36 | }, 37 | "prefer-stable": true, 38 | "autoload": { 39 | "psr-4": { 40 | "Salman\\GeoCode\\": "src/" 41 | }, 42 | "files": [ 43 | "src/Helper/Helpers.php" 44 | ] 45 | }, 46 | "extra": { 47 | "laravel": { 48 | "providers": [ 49 | "Salman\\GeoCode\\GeoCodeServiceProvider" 50 | ], 51 | "aliases": { 52 | "GeoCode": "Salman\\GeoCode\\Facades\\GeoCode" 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Facades/GeoCode.php: -------------------------------------------------------------------------------- 1 | publishConfig(); 24 | } 25 | 26 | public function register() 27 | { 28 | $this->app->singleton('GeoCode',function (){ 29 | 30 | return new GeoCode(); 31 | }); 32 | } 33 | 34 | /** 35 | * @return array 36 | */ 37 | public function provides() 38 | { 39 | return array('GeoCode'); 40 | } 41 | /* 42 | * Publish Config File 43 | */ 44 | public function publishConfig() 45 | { 46 | $this->mergeConfigFrom(__DIR__.'/config/geocode.php','geocode'); 47 | $this->publishes([ 48 | __DIR__.'/config/geocode.php' => config_path('geocode.php'), 49 | ]); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Helper/Helpers.php: -------------------------------------------------------------------------------- 1 | getLatAndLong($address); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Services/GeoCode.php: -------------------------------------------------------------------------------- 1 | API_KEY = config('geocode.API_KEY'); 13 | } 14 | 15 | public function getLatAndLong($address) 16 | { 17 | return GeoCodeService::findPoints($address, $this->API_KEY); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Services/GeoCodeService.php: -------------------------------------------------------------------------------- 1 | $address, 21 | "key" => $key 22 | ];*/ 23 | 24 | return self::makeRequest($urlWithData); 25 | 26 | } 27 | 28 | 29 | protected static function makeRequest($urlWithData) 30 | { 31 | // return $urlWithData; 32 | 33 | $cURLConnection = curl_init(); 34 | 35 | curl_setopt($cURLConnection, CURLOPT_URL, $urlWithData); 36 | curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true); 37 | 38 | $data = curl_exec($cURLConnection); 39 | 40 | curl_close($cURLConnection); 41 | 42 | $finalData = json_decode($data, true); 43 | 44 | if ($finalData) 45 | { 46 | if ($finalData['status'] === "OK") 47 | { 48 | return collect($finalData['results'][0]); 49 | } 50 | elseif ($finalData['status'] == "ZERO_RESULTS") 51 | { 52 | return false; 53 | } 54 | 55 | return $finalData['error_message']; 56 | } 57 | 58 | return false; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/config/geocode.php: -------------------------------------------------------------------------------- 1 | env('GOOGLE_GEOCODE_API_KEY', null), 12 | ]; 13 | --------------------------------------------------------------------------------