{"id":27019323,"url":"https://github.com/opencagedata/php-opencage-geocode","last_synced_at":"2025-04-04T17:27:12.842Z","repository":{"id":16314498,"uuid":"19063515","full_name":"OpenCageData/php-opencage-geocode","owner":"OpenCageData","description":"PHP library to access the OpenCage geocoding API","archived":false,"fork":false,"pushed_at":"2024-11-21T21:47:37.000Z","size":127,"stargazers_count":33,"open_issues_count":0,"forks_count":9,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-27T09:17:31.857Z","etag":null,"topics":["geocoding","opencage","opencage-geocoder","php"],"latest_commit_sha":null,"homepage":"https://opencagedata.com/tutorials/geocode-in-php","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"Hektve87/hello-world","license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OpenCageData.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.txt","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-04-23T09:06:35.000Z","updated_at":"2024-12-02T17:08:19.000Z","dependencies_parsed_at":"2024-06-18T15:27:00.512Z","dependency_job_id":"22f22007-fc67-4da4-89ef-70630d2b3a2e","html_url":"https://github.com/OpenCageData/php-opencage-geocode","commit_stats":{"total_commits":60,"total_committers":5,"mean_commits":12.0,"dds":0.3666666666666667,"last_synced_commit":"0b3a80e8075d2880efdb6da8150babc486309b3c"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenCageData%2Fphp-opencage-geocode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenCageData%2Fphp-opencage-geocode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenCageData%2Fphp-opencage-geocode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenCageData%2Fphp-opencage-geocode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OpenCageData","download_url":"https://codeload.github.com/OpenCageData/php-opencage-geocode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247219596,"owners_count":20903478,"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":["geocoding","opencage","opencage-geocoder","php"],"created_at":"2025-04-04T17:27:12.128Z","updated_at":"2025-04-04T17:27:12.826Z","avatar_url":"https://github.com/OpenCageData.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OpenCage Geocoding API Library for PHP\n\nA [PHP](http://php.net/) library to use the [OpenCage geocoding API](https://opencagedata.com/api).\n\n## Build Status / Code Quality\n\n[![Build Status](https://github.com/OpenCageData/php-opencage-geocode/actions/workflows/ci.yml/badge.svg)](https://github.com/OpenCageData/php-opencage-geocode/actions/workflows/ci.yml)\n[![PHP version](https://badge.fury.io/ph/opencage%2Fgeocode.svg)](https://badge.fury.io/ph/opencage%2Fgeocode)\n![Mastodon Follow](https://img.shields.io/mastodon/follow/109287663468501769?domain=https%3A%2F%2Fen.osm.town%2F\u0026style=social)\n\n## Overview\nThis library attempts to use the [CURL](http://www.php.net/manual/en/book.curl.php)\nextension to access the OpenCage Geocoding API. If CURL support is not available, the\nlibrary falls back to using [fopen wrappers](http://uk3.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen).\n\nTo use the library you must either have the CURL extension compiled into your version\nof PHP. Alternatively configure the use of fopen wrappers via the `allow_url_fopen`\ndirective in your `php.ini`.\n\n### Authentication\n\nYou need an API key, which you can sign up for [here](https://opencagedata.com).\n\n### Tutorial\n\nYou can find [a comprehensive tutorial for using this module on the OpenCage site](https://opencagedata.com/tutorials/geocode-in-php).\n\n## Installation\n\n### With Composer\n\nThe recommended - and easiest way - to install is via [Composer](https://getcomposer.org/).\nRequire the library in your project's `composer.json` file.\n\n```php\n$ composer require opencage/geocode\n```\n\nImport the Geocoder class.\n\n```php\nrequire \"vendor/autoload.php\";\n```\n\n### The old fashioned way\n\nSee the file `demo/geocode.php`\n\n\n## Geocoding\n\n```php\n$geocoder = new \\OpenCage\\Geocoder\\Geocoder('YOUR-API-KEY');\n$result = $geocoder-\u003egeocode('82 Clerkenwell Road, London');\nprint_r($result);\n```\n\n### Reverse geocoding\n\n```php\n$geocoder = new \\OpenCage\\Geocoder\\Geocoder('YOUR-API-KEY');\n$result = $geocoder-\u003egeocode('43.831,4.360'); # latitude,longitude (y,x)\nprint $result['results'][0]['formatted'];\n// 3 Rue de Rivarol, 30020 Nîmes, France\n```\n\n### Set optional parameters\n\nSee the full list at:\n[https://opencagedata.com/api#optional-params](https://opencagedata.com/api#optional-params)\n\n```php\n$result = $geocoder-\u003egeocode('6 Rue Massillon, 30020 Nîmes, France', [\n    'language' =\u003e 'fr',\n    'countrycode' =\u003e 'fr'\n]);\nif ($result \u0026\u0026 $result['total_results'] \u003e 0) {\n  $first = $result['results'][0];\n  print $first['geometry']['lng'] . ';' . $first['geometry']['lat'] . ';' . $first['formatted'] . \"\\n\";\n  // 4.360081;43.8316276;6 Rue Massillon, 30020 Nîmes, Frankreich\n}\n```\n\n### Set a proxy URL\n\n```php\n$geocoder-\u003esetProxy('http://proxy.example.com:1234');\n$result = $geocoder-\u003egeocode(\"Brandenburger Tor, Berlin\");\nprint_r($result['results'][0]['formatted']);\n// Brandenburger Tor, Unter den Linden, 10117 Berlin, Germany\nprint_r($result['results'][0]['geometry']);\n// Array\n// (\n//    [lat] =\u003e 52.5166047\n//    [lng] =\u003e 13.3809897\n// )\n```\n\n## Example results\n\n\n```php\nArray\n(\n    [total_results] =\u003e 2\n    [status] =\u003e Array\n        (\n            [message] =\u003e OK\n            [code] =\u003e 200\n        )\n    [results] =\u003e Array\n        (\n            [0] =\u003e Array\n                (\n                    [annotations] =\u003e Array\n                        (\n                            [DMS] =\u003e Array\n                                (\n                                    [lat] =\u003e 51° 31' 21.60894'' N\n                                    [lng] =\u003e 0° 6' 8.95198'' E\n                                )\n\n                            [MGRS] =\u003e 30UYC0100511930\n                            [Maidenhead] =\u003e IO91wm75qk\n                            [Mercator] =\u003e Array\n                                (\n                                    [x] =\u003e -11408.763\n                                    [y] =\u003e 6680801.955\n                                )\n\n                            [OSGB] =\u003e Array\n                                (\n                                    [easting] =\u003e 531628.199\n                                    [gridref] =\u003e TQ 316 821\n                                    [northing] =\u003e 182177.015\n                                )\n\n                            [OSM] =\u003e Array\n                                (\n                                    [url] =\u003e http://www.openstreetmap.org/?mlat=51.52267\u0026mlon=-0.10249#map=17/51.52267/-0.10249\n                                )\n\n                            [callingcode] =\u003e 44\n                            [geohash] =\u003e gcpvjemm7csmhczg9cvt\n                            [sun] =\u003e Array\n                                (\n                                    [rise] =\u003e Array\n                                        (\n                                            [apparent] =\u003e 1452931140\n                                            [astronomical] =\u003e 1452923940\n                                            [civil] =\u003e 1452928800\n                                            [nautical] =\u003e 1452926280\n                                        )\n\n                                    [set] =\u003e Array\n                                        (\n                                            [apparent] =\u003e 1452961320\n                                            [astronomical] =\u003e 1452968520\n                                            [civil] =\u003e 1452963660\n                                            [nautical] =\u003e 1452966120\n                                        )\n\n                                )\n\n                            [timezone] =\u003e Array\n                                (\n                                    [name] =\u003e Europe/London\n                                    [now_in_dst] =\u003e 0\n                                    [offset_sec] =\u003e 0\n                                    [offset_string] =\u003e 0\n                                    [short_name] =\u003e GMT\n                                )\n\n                            [what3words] =\u003e Array\n                                (\n                                    [words] =\u003e gallons.trim.tips\n                                )\n\n                        )\n\n                    [bounds] =\u003e Array\n                        (\n                            [northeast] =\u003e Array\n                                (\n                                    [lat] =\u003e 51.5227563\n                                    [lng] =\u003e -0.1023801\n                                )\n\n                            [southwest] =\u003e Array\n                                (\n                                    [lat] =\u003e 51.5226042\n                                    [lng] =\u003e -0.1025907\n                                )\n\n                        )\n\n                    [components] =\u003e Array\n                        (\n                            [city] =\u003e London\n                            [country] =\u003e United Kingdom\n                            [country_code] =\u003e gb\n                            [house_number] =\u003e 82\n                            [postcode] =\u003e EC1M 5RF\n                            [road] =\u003e Clerkenwell Road\n                            [state] =\u003e England\n                            [state_district] =\u003e Greater London\n                            [suburb] =\u003e Clerkenwell\n                        )\n\n                    [confidence] =\u003e 10\n                    [formatted] =\u003e 82 Clerkenwell Road, London EC1M 5RF, United Kingdom\n                    [geometry] =\u003e Array\n                        (\n                            [lat] =\u003e 51.52266915\n                            [lng] =\u003e -0.10248666188363\n                        )\n\n                )\n\n            [1] =\u003e Array\n                (\n                    [annotations] =\u003e Array\n                        (\n                            [DMS] =\u003e Array\n                                (\n                                    [lat] =\u003e 51° 30' 30.70800'' N\n                                    [lng] =\u003e 0° 7' 32.66400'' E\n                                )\n\n                            [MGRS] =\u003e 30UXC9945410295\n                            [Maidenhead] =\u003e IO91wm42vb\n                            [Mercator] =\u003e Array\n                                (\n                                    [x] =\u003e -13997.313\n                                    [y] =\u003e 6678279.278\n                                )\n\n                            [OSGB] =\u003e Array\n                                (\n                                    [easting] =\u003e 530055.544\n                                    [gridref] =\u003e TQ 300 805\n                                    [northing] =\u003e 180563.298\n                                )\n\n                            [OSM] =\u003e Array\n                                (\n                                    [url] =\u003e http://www.openstreetmap.org/?mlat=51.50853\u0026mlon=-0.12574#map=17/51.50853/-0.12574\n                                )\n\n                            [geohash] =\u003e gcpvj0u6yjcmwxz8bn43\n                            [sun] =\u003e Array\n                                (\n                                    [rise] =\u003e Array\n                                        (\n                                            [apparent] =\u003e 1452931140\n                                            [astronomical] =\u003e 1452923940\n                                            [civil] =\u003e 1452928800\n                                            [nautical] =\u003e 1452926340\n                                        )\n\n                                    [set] =\u003e Array\n                                        (\n                                            [apparent] =\u003e 1452961320\n                                            [astronomical] =\u003e 1452968520\n                                            [civil] =\u003e 1452963660\n                                            [nautical] =\u003e 1452966120\n                                        )\n\n                                )\n\n                            [timezone] =\u003e Array\n                                (\n                                    [name] =\u003e Europe/London\n                                    [now_in_dst] =\u003e 0\n                                    [offset_sec] =\u003e 0\n                                    [offset_string] =\u003e 0\n                                    [short_name] =\u003e GMT\n                                )\n\n                            [what3words] =\u003e Array\n                                (\n                                    [words] =\u003e thing.then.link\n                                )\n\n                        )\n\n                    [bounds] =\u003e Array\n                        (\n                            [northeast] =\u003e Array\n                                (\n                                    [lat] =\u003e 51.7202301025\n                                    [lng] =\u003e 0.336111992598\n                                )\n\n                            [southwest] =\u003e Array\n                                (\n                                    [lat] =\u003e 51.2786598206\n                                    [lng] =\u003e -0.523222982883\n                                )\n\n                        )\n\n                    [components] =\u003e Array\n                        (\n                            [country] =\u003e United Kingdom\n                            [county] =\u003e Greater London\n                            [state] =\u003e England\n                            [town] =\u003e London\n                        )\n\n                    [confidence] =\u003e 1\n                    [formatted] =\u003e London, Greater London, United Kingdom\n                    [geometry] =\u003e Array\n                        (\n                            [lat] =\u003e 51.50853\n                            [lng] =\u003e -0.12574\n                        )\n\n                )\n\n        )\n)\n```\n\n## Copyright\n\nCopyright (c) OpenCage GmbH. See LICENSE for details.\n\n## Who is OpenCage GmbH?\n\n\u003ca href=\"https://opencagedata.com\"\u003e\u003cimg src=\"opencage_logo_300_150.png\"\u003e\u003c/a\u003e\n\nWe run a worldwide [geocoding API](https://opencagedata.com/api) and [geosearch](https://opencagedata.com/geosearch) service based on open data. \nLearn more [about us](https://opencagedata.com/about). \n\nWe also run [Geomob](https://thegeomob.com), a series of regular meetups for location based service creators, where we do our best to highlight geoinnovation. If you like geo stuff, you will probably enjoy [the Geomob podcast](https://thegeomob.com/podcast/).\n\n-- end --\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopencagedata%2Fphp-opencage-geocode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopencagedata%2Fphp-opencage-geocode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopencagedata%2Fphp-opencage-geocode/lists"}