{"id":13584704,"url":"https://github.com/spatie/geocoder","last_synced_at":"2025-05-13T21:03:50.769Z","repository":{"id":16600870,"uuid":"19355432","full_name":"spatie/geocoder","owner":"spatie","description":"Geocode addresses to coordinates","archived":false,"fork":false,"pushed_at":"2025-04-08T14:27:43.000Z","size":160,"stargazers_count":797,"open_issues_count":0,"forks_count":113,"subscribers_count":20,"default_branch":"main","last_synced_at":"2025-04-28T12:04:41.519Z","etag":null,"topics":["address","geo","geocoder","google","php"],"latest_commit_sha":null,"homepage":"https://spatie.be/opensource","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"facebook/facebook-android-sdk","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"custom":"https://spatie.be/open-source/support-us"}},"created_at":"2014-05-01T19:37:31.000Z","updated_at":"2025-04-27T11:54:54.000Z","dependencies_parsed_at":"2025-03-02T18:03:03.515Z","dependency_job_id":"6a6d6f3c-49a3-4487-a691-e3b0c970c4e2","html_url":"https://github.com/spatie/geocoder","commit_stats":{"total_commits":189,"total_committers":44,"mean_commits":4.295454545454546,"dds":"0.46031746031746035","last_synced_commit":"18abcad291a9208d133463f374d603290b511dcf"},"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fgeocoder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fgeocoder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fgeocoder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fgeocoder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/geocoder/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251311330,"owners_count":21569009,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["address","geo","geocoder","google","php"],"created_at":"2024-08-01T15:04:27.670Z","updated_at":"2025-04-28T12:04:46.736Z","avatar_url":"https://github.com/spatie.png","language":"PHP","readme":"\u003cdiv align=\"left\"\u003e\n    \u003ca href=\"https://spatie.be/open-source?utm_source=github\u0026utm_medium=banner\u0026utm_campaign=geocoder\" target=\"_blank\"\u003e\n      \u003cpicture\u003e\n        \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://spatie.be/packages/header/geocoder/html/dark.webp\"\u003e\n        \u003cimg alt=\"Logo for Geocoder\" src=\" https://spatie.be/packages/header/geocoder/html/light.webp\" height=\"190\"\u003e\n      \u003c/picture\u003e\n    \u003c/a\u003e\n\n\u003ch1\u003eGeocode Addresses into Coordinates\u003c/h1\u003e\n    \n[![Latest Version](https://img.shields.io/github/release/spatie/geocoder.svg?style=flat-square)](https://github.com/spatie/geocoder/releases)\n[![MIT Licensed](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![run-tests](https://github.com/spatie/geocoder/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/geocoder/actions/workflows/run-tests.yml)\n![Check \u0026 fix styling](https://github.com/spatie/geocoder/workflows/Check%20\u0026%20fix%20styling/badge.svg)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/geocoder.svg?style=flat-square)](https://packagist.org/packages/spatie/geocoder)\n    \n\u003c/div\u003e\n\nThis package can convert any address to GPS coordinates using [Google's geocoding service](https://developers.google.com/maps/documentation/geocoding/start). Here's a quick example:\n\n```php\nGeocoder::getCoordinatesForAddress('Samberstraat 69, Antwerpen, Belgium');\n\n// will return this array\n[\n   'lat' =\u003e 51.2343564,\n   'lng' =\u003e 4.4286108,\n   'accuracy' =\u003e 'ROOFTOP',\n   'formatted_address' =\u003e 'Samberstraat 69, 2060 Antwerpen, Belgium',\n   'viewport' =\u003e [\n       \"northeast\" =\u003e [\n            \"lat\" =\u003e 51.23570538029149,\n            \"lng\" =\u003e 4.429959780291502\n        ],\n        \"southwest\" =\u003e [\n            \"lat\" =\u003e 51.2330074197085,\n            \"lng\" =\u003e 4.427261819708497\n        ]\n   ]\n]\n```\n\n## Support us\n\nLearn how to create a package like this one, by watching our premium video course:\n\n[![Laravel Package training](https://spatie.be/github/package-training.jpg)](https://laravelpackage.training)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Installation\n\nYou can install this package through composer.\n\n```bash\ncomposer require spatie/geocoder\n```\n## Laravel installation\n\nThough the package works fine in non-Laravel projects we included some niceties for our fellow artistans.\n\nIn Laravel 5.5 the package will autoregister itself. In older versions of Laravel you must manually install the service provider and facade.\n\n```php\n// config/app.php\n'providers' =\u003e [\n    '...',\n    Spatie\\Geocoder\\GeocoderServiceProvider::class\n];\n```\n\n```php\n// config/app.php\n'aliases' =\u003e array(\n\t...\n\t'Geocoder' =\u003e Spatie\\Geocoder\\Facades\\Geocoder::class,\n)\n```\n\nNext, you must publish the config file :\n\n```bash\nphp artisan vendor:publish --provider=\"Spatie\\Geocoder\\GeocoderServiceProvider\" --tag=\"config\"\n```\n\nThis is the content of the config file:\n\n```php\nreturn [\n\n   /*\n    * The api key used when sending Geocoding requests to Google.\n    */\n   'key' =\u003e env('GOOGLE_MAPS_GEOCODING_API_KEY', ''),\n\n\n   /*\n    * The language param used to set response translations for textual data.\n    *\n    * More info: https://developers.google.com/maps/faq#languagesupport\n    */\n\n   'language' =\u003e '',\n\n   /*\n    * The region param used to finetune the geocoding process.\n    *\n    * More info: https://developers.google.com/maps/documentation/geocoding/intro#RegionCodes\n    */\n   'region' =\u003e '',\n\n    /*\n     * The bounds param used to finetune the geocoding process.\n     *\n     * More info: https://developers.google.com/maps/documentation/geocoding/intro#Viewports\n     */\n    'bounds' =\u003e '',\n    \n     /*\n     * The country param used to limit results to a specific country.\n     *\n     * More info: https://developers.google.com/maps/documentation/javascript/geocoding#GeocodingRequests\n     */\n    'country' =\u003e '',\n];\n```\n\n## Usage\n\nHere's how you can use the Geocoder.\n\n```php\n$client = new \\GuzzleHttp\\Client();\n\n$geocoder = new Geocoder($client);\n\n$geocoder-\u003esetApiKey(config('geocoder.key'));\n\n$geocoder-\u003esetCountry(config('geocoder.country', 'US'));\n\n$geocoder-\u003egetCoordinatesForAddress('Infinite Loop 1, Cupertino');\n\n/*\n  This function returns an array with keys\n  \"lat\" =\u003e  37.331741000000001\n  \"lng\" =\u003e -122.0303329\n  \"accuracy\" =\u003e \"ROOFTOP\"\n  \"formatted_address\" =\u003e \"1 Infinite Loop, Cupertino, CA 95014, USA\",\n  \"viewport\" =\u003e [\n    \"northeast\" =\u003e [\n      \"lat\" =\u003e 37.3330546802915,\n      \"lng\" =\u003e -122.0294342197085\n    ],\n    \"southwest\" =\u003e [\n      \"lat\" =\u003e 37.3303567197085,\n      \"lng\" =\u003e -122.0321321802915\n    ]\n  ]\n*/\n```\n\nYou can get the result back in a specific language.\n\n```php\n$geocoder-\u003esetLanguage('it');\n\n$geocoder-\u003egetCoordinatesForAddress('Infinite Loop 1, Cupertino');\n\n/*\n  This function returns an array with keys\n  \"lat\" =\u003e 37,3318598\n  \"lng\" =\u003e -122,0302485\n  \"accuracy\" =\u003e \"ROOFTOP\"\n  \"formatted_address\" =\u003e \"Infinite Loop 1, 1 Infinite Loop, Cupertino, CA 95014, Stati Uniti\"\n  ...\n*/\n```\n\nYou can also get all the results instead of the first one\n```php\n$geocoder\n   -\u003egetAllCoordinatesForAddress('Infinite Loop 1, Cupertino');\n\n/*\n  This function returns an array of results (array of array)\n  ^ array:2 [\n      0 =\u003e array:7 [\n        \"lat\" =\u003e 37,3318115\n        \"lng\" =\u003e -122,0301837\n        \"accuracy\" =\u003e \"ROOFTOP\"\n        \"formatted_address\" =\u003e \"1 Infinite Loop, Cupertino, CA 95014, Stati Uniti\"\n        \"viewport\" =\u003e [\n          \"northeast\" =\u003e [\n            \"lat\" =\u003e 37.3330546802915,\n            \"lng\" =\u003e -122.0294342197085\n          ],\n          \"southwest\" =\u003e [\n            \"lat\" =\u003e 37.3303567197085,\n            \"lng\" =\u003e -122.0321321802915\n          ]\n        ]\n        \"place_id\" =\u003e \"ChIJHTRqF7e1j4ARzZ_Fv8VA4Eo\"\n      ]\n      1 =\u003e array:7 [\n        \"lat\" =\u003e 37,3318598\n        \"lng\" =\u003e -122,0302485\n        \"accuracy\" =\u003e \"ROOFTOP\"\n        \"formatted_address\" =\u003e \"Infinite Loop 1, 1 Infinite Loop, Cupertino, CA 95014, Stati Uniti\"\n        \"viewport\" =\u003e [\n          \"northeast\" =\u003e [\n            \"lat\" =\u003e 37.333046180291\n            \"lng\" =\u003e -122.02883961971\n          ],\n          \"southwest\" =\u003e [\n            \"lat\" =\u003e 37.330348219708\n            \"lng\" =\u003e -122.03153758029\n          ]\n        ]\n        \"place_id\" =\u003e \"ChIJAf9D3La1j4ARuwKZtGjgMXw\"\n      ]\n    ]\n*/\n```\n\nThis is how you can reverse geocode coordinates to addresses.\n\n```php\n$geocoder-\u003egetAddressForCoordinates(40.714224, -73.961452);\n\n/*\n  This function returns an array with keys\n  \"lat\" =\u003e 40.7142205\n  \"lng\" =\u003e -73.9612903\n  \"accuracy\" =\u003e \"ROOFTOP\"\n  \"formatted_address\" =\u003e \"277 Bedford Ave, Brooklyn, NY 11211, USA\",\n  \"viewport\" =\u003e [\n    \"northeast\" =\u003e [\n      \"lat\" =\u003e 37.3330546802915,\n      \"lng\" =\u003e -122.0294342197085\n    ],\n    \"southwest\" =\u003e [\n      \"lat\" =\u003e 37.3303567197085,\n      \"lng\" =\u003e -122.0321321802915\n    ]\n  ]\n*/\n```\n\nYou can also reverse geocode coordinates to all the related addresses.\n\n```php\n$geocoder-\u003egetAllAddressesForCoordinates(40.714224, -73.961452);\n\n/*\n  This function returns an array of results (array of array)\n  array:2 [\n    0 =\u003e array: 7 [\n      \"lat\" =\u003e 40.7142205\n      \"lng\" =\u003e -73.9612903\n      \"accuracy\" =\u003e \"ROOFTOP\"\n      \"formatted_address\" =\u003e \"277 Bedford Ave, Brooklyn, NY 11211, USA\",\n      \"viewport\" =\u003e [\n        \"northeast\" =\u003e [\n          \"lat\" =\u003e 37.3330546802915,\n          \"lng\" =\u003e -122.0294342197085\n        ],\n        \"southwest\" =\u003e [\n          \"lat\" =\u003e 37.3303567197085,\n          \"lng\" =\u003e -122.0321321802915\n        ]\n      ]\n    ],\n    1 =\u003e array: 7 [\n      \"lat\" =\u003e 40.7142015\n      \"lng\" =\u003e -73.9613077\n      \"accuracy\" =\u003e \"ROOFTOP\"\n      \"formatted_address\" =\u003e \"279 Bedford Ave, Brooklyn, NY 11211, USA\",\n      \"viewport\" =\u003e [\n        \"northeast\" =\u003e [\n          \"lat\" =\u003e 40.715557080291,\n          \"lng\" =\u003e -73.959947169708\n        ],\n        \"southwest\" =\u003e [\n          \"lat\" =\u003e 40.712859119708,\n          \"lng\" =\u003e -73.962645130291\n        ]\n      ]\n    ]\n  ]\n*/\n```\n\nIf you are using the package with Laravel, you can simply call `getCoordinatesForAddress`.\n\n```php\nGeocoder::getCoordinatesForAddress('Infinite Loop 1, Cupertino');\n\n/*\n  This function returns an array with keys\n  \"lat\" =\u003e  37.331741000000001\n  \"lng\" =\u003e -122.0303329\n  \"accuracy\" =\u003e \"ROOFTOP\"\n  \"formatted_address\" =\u003e \"1 Infinite Loop, Cupertino, CA 95014, Stati Uniti\",\n    \"viewport\" =\u003e [\n    \"northeast\" =\u003e [\n      \"lat\" =\u003e 37.3330546802915,\n      \"lng\" =\u003e -122.0294342197085\n    ],\n    \"southwest\" =\u003e [\n      \"lat\" =\u003e 37.3303567197085,\n      \"lng\" =\u003e -122.0321321802915\n    ]\n  ]\n*/\n```\n\nThe accuracy key can contain these values:\n- `ROOFTOP`\n- `RANGE_INTERPOLATED`\n- `GEOMETRIC_CENTER`\n- `APPROXIMATE`\n\nYou can read more information about these values [on the Google Geocoding API Page](https://developers.google.com/maps/documentation/geocoding/ \"Google Geocoding API\")\n\nWhen an address is not found accuracy and formatted_address will contain `result_not_found`\n\n## Credits\n\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","funding_links":["https://spatie.be/open-source/support-us"],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fgeocoder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Fgeocoder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fgeocoder/lists"}