{"id":15067048,"url":"https://github.com/alexpechkarev/google-maps","last_synced_at":"2025-05-14T02:05:55.608Z","repository":{"id":1213613,"uuid":"41380230","full_name":"alexpechkarev/google-maps","owner":"alexpechkarev","description":"Collection of Google Maps API Web Services for Laravel","archived":false,"fork":false,"pushed_at":"2025-04-29T18:10:23.000Z","size":216,"stargazers_count":548,"open_issues_count":0,"forks_count":117,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-05-06T04:03:30.203Z","etag":null,"topics":["google-maps","laravel","php"],"latest_commit_sha":null,"homepage":"http://alexpechkarev.github.io/google-maps/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexpechkarev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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}},"created_at":"2015-08-25T18:18:18.000Z","updated_at":"2025-05-05T11:24:43.000Z","dependencies_parsed_at":"2024-06-18T12:15:59.259Z","dependency_job_id":"aae5da5a-6b94-4023-a7f6-4ffad0343809","html_url":"https://github.com/alexpechkarev/google-maps","commit_stats":{"total_commits":145,"total_committers":23,"mean_commits":6.304347826086956,"dds":"0.29655172413793107","last_synced_commit":"7b0443b873449d21ca903d7a5aa075be795dec47"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexpechkarev%2Fgoogle-maps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexpechkarev%2Fgoogle-maps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexpechkarev%2Fgoogle-maps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexpechkarev%2Fgoogle-maps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexpechkarev","download_url":"https://codeload.github.com/alexpechkarev/google-maps/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252810271,"owners_count":21807760,"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":["google-maps","laravel","php"],"created_at":"2024-09-25T01:15:41.325Z","updated_at":"2025-05-14T02:05:50.589Z","avatar_url":"https://github.com/alexpechkarev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Collection of Google Maps API Web Services for Laravel\n\nProvides a convenient way of setting up and making requests to Google Maps APIs from your [Laravel](http://laravel.com/) application.\n\nFor services documentation, API key usage limits, and terms of service, please refer to the official Google Maps documentation:\n- [Google Maps API Web Services](https://developers.google.com/maps/documentation/webservices/)\n- [Maps API Terms of Service \u0026 License Restrictions](https://developers.google.com/maps/terms#section_10_12).\n\n---\n\n### Important Update: Routes API replaces Directions \u0026 Distance Matrix\n\n**The Google Maps Directions API and Distance Matrix API are deprecated.**\n\nThis package now includes support for the **new Google Maps Routes API**, which is the recommended replacement for calculating routes and route matrices. The Routes API offers enhanced features and performance.\n\n**Please update your application code to use the `routes` and `routematrix` services provided by this package instead of the deprecated `directions` and `distancematrix` services.**\n\n---\n\n## Features\nThis package provides easy access to the following Google Maps APIs:\n\n- **[Routes API](https://developers.google.com/maps/documentation/routes/route-usecases) (Recommended replacement for Directions \u0026 Distance Matrix)**\n    - `routes`: Compute routes between locations.\n    - `routematrix`: Compute route matrices between origins and destinations.\n- [Elevation API](https://developers.google.com/maps/documentation/elevation/)\n- [Geocoding API](https://developers.google.com/maps/documentation/geocoding/)\n- [Geolocation API](https://developers.google.com/maps/documentation/geolocation/)\n- [Roads API](https://developers.google.com/maps/documentation/roads/)\n- [Time Zone API](https://developers.google.com/maps/documentation/timezone/)\n- [Places API Web Services](https://developers.google.com/places/web-service/)\n\n---\n\n## Dependency\n\n- [PHP cURL](http://php.net/manual/en/curl.installation.php)\n- [PHP \u003e= 7.3.0](http://php.net/)\n\n\n## API Deprecation Notes\n\nIn addition to the Directions and Distance Matrix deprecation mentioned above:\n\n**Places API:**\n- **Removed Features:** Requests attempting to use Place Add, Place Delete, or Radar Search will receive an error. [More Info](https://cloud.google.com/blog/products/maps-platform/announcing-deprecation-of-place-add)\n- **Deprecated Parameters/Fields:**\n    - Nearby Search: The `types` parameter is deprecated; use the `type` parameter (string) instead.\n    - Place Details: The `reference` field is deprecated; use `placeid` (this package uses `placeid` by default).\n    - Place Add \u0026 Place Autocomplete: Still use the `types` parameter as per Google's documentation (links provided in the original README).\n\n---\n\n## Installation\n\nIssue following command in console:\n\n```php\ncomposer require alexpechkarev/google-maps\n```\n\n## Configuration\n\nRegister Service Provider \u0026 Facade (in `config/app.php`):\n\n```php\n'providers' =\u003e [\n    ...\n    GoogleMaps\\ServiceProvider\\GoogleMapsServiceProvider::class,\n]\n\n'aliases' =\u003e [\n    ...\n    'GoogleMaps' =\u003e GoogleMaps\\Facade\\GoogleMapsFacade::class,\n]\n```\n\nPublish configuration file:\n\n```php\nphp artisan vendor:publish --tag=googlemaps\n```\n\nAdd API Key: Open **config/googlemaps.php*** and add your Google Maps API key:\n\n```php\n/*\n|----------------------------------\n| Service Keys\n|------------------------------------\n*/\n\n'key'       =\u003e 'ADD YOUR SERVICE KEY HERE',\n```\n\nIf you like to use different keys for any of the services, you can overwrite master API Key by specifying it in the `service` array for selected web service.\n\n## Usage\n\nGeneral Pattern:\nLoad the desired service using `\\GoogleMaps::load('service-name')`.\nSet parameters using `setParam([...])` or `setParamByKey('key', 'value')`.\nExecute the request:\n- Use `-\u003eget()` for all APIs EXCEPT the Routes API.\n- Use `-\u003efetch()` ONLY for the Routes API (routes and routematrix services).\n\n#### Example: Geocoding API (using `get()`):\n```php\n$response = \\GoogleMaps::load('geocoding')\n\t\t-\u003esetParam (['address' =\u003e'santa cruz'])\n \t\t-\u003eget();\n```\n\nBy default, where appropriate, `output` parameter set to `JSON`. Don't forget to decode JSON string into PHP variable.\n\n\n#### Example: Routes API - Compute Route (using `fetch()`):\n\nNote: The Routes API uses the fetch() method and returns a PHP array directly (no JSON decoding needed).\nNote: The config for routes includes a decodePolyline parameter (default true), which adds a decodedPolyline key to the response if a polyline is present.\n\n```php\n$routeParams = [\n    'origin' =\u003e [ /* ... origin details ... */ ],\n    'destination' =\u003e [ /* ... destination details ... */ ],\n    'travelMode' =\u003e 'DRIVE',\n    // ... other Routes API parameters ...\n];\n\n$responseArray = \\GoogleMaps::load('routes') // Use 'routes' service\n    -\u003esetParam($routeParams)\n    -\u003esetFieldMask('routes.duration,routes.distanceMeters,routes.polyline.encodedPolyline') // optional - used to specify fields to return \n    -\u003efetch(); // Use fetch() for Routes API\n\n// $responseArray is already a PHP array\nif (!empty($responseArray['routes'])) {\n    // Process the route data\n} else {\n    // Handle errors or no routes found\n}\n```\n\n#### Example: Routes API - Compute Route Matrix (using `fetch()`):\n\n```php\n$matrixParams = [\n    'origins' =\u003e [ /* ... array of origins ... */ ],\n    'destinations' =\u003e [ /* ... array of destinations ... */ ],\n    'travelMode' =\u003e 'DRIVE',\n    // ... other Route Matrix parameters ...\n];\n\n$responseArray = \\GoogleMaps::load('routematrix') // Use 'routematrix' service\n    -\u003esetParam($matrixParams)\n    -\u003esetFieldMask('originIndex,destinationIndex,duration,distanceMeters,status,condition') // optional - used to specify fields to return \n    -\u003efetch(); // Use fetch() for Routes API\n\n// $responseArray is already a PHP array\n// Process the matrix data\n```\n\nRequired parameters can be specified as an array of `key:value` pairs\n\n```php\n$response = \\GoogleMaps::load('geocoding')\n\t\t-\u003esetParam ([\n\t\t    'address'    =\u003e'santa cruz',\n            'components' =\u003e [\n                    'administrative_area'  =\u003e 'TX',\n                    'country'              =\u003e 'US',\n                    ]\n                ])\n                -\u003eget();\n```\n\nAlternatively parameters can be set using `setParamByKey()` method. For deeply nested array use \"dot\" notation as per example below.\n\n```php\n$endpoint = \\GoogleMaps::load('geocoding')\n   -\u003esetParamByKey('address', 'santa cruz')\n   -\u003esetParamByKey('components.administrative_area', 'TX') //return $this\n    ...\n```\n\n\n\n\n## Available methods\n\n- [`load( $serviceName )`](#load): Loads the specified web service configuration. Returns $this.\n- [`setEndpoint( $endpoint )`](#setEndpoint): Sets the desired response format (json or xml) for APIs using get(). Default is json. Not applicable to Routes API (fetch()). Returns $this.\n- [`getEndpoint()`](#getEndpoint): Gets the currently configured endpoint format (json or xml).\n- [`setParamByKey( $key, $value)`](#setParamByKey): Sets a single request parameter. Use 'dot' notation for nested arrays (e.g., components.country). Returns $this.\n- [`setParam( $parameters)`](#setParam): Sets multiple request parameters from an array. Returns $this.\n- [`get()`](#get): (**For all APIs EXCEPT Routes API**) Executes the request. Returns a JSON string (or XML string if configured). If $key is provided (using 'dot' notation), attempts to return only that part of the response.\n- [`fetch()`](#fetch): (**ONLY for Routes API** - `routes` and `routematrix`) Executes the request against the Routes API. Returns a decoded PHP array directly or throws an `ErrorException`.\n- [`containsLocation( $lat, $lng )`](#containsLocation): (**Routes API only**) Checks if a point falls within the polygon returned by a routes API call. Requires a prior `setParam()` call for the route. Returns boolean.\n- [`isLocationOnEdge( $lat, $lng, $tolrance)`](#isLocationOnEdge): (**Routes API only**) Checks if a point falls on or near the polyline returned by a routes API call. Requires a prior `setParam()` call for the route. Returns boolean.\n\n---\n\n\u003ca name=\"load\"\u003e\u003c/a\u003e\n**`load( $serviceName )`** - load web service by name\n\nAccepts string as parameter, web service name as specified in configuration file.\nReturns reference to it's self.\n\n```php\n\\GoogleMaps::load('geocoding')\n...\n```\n\n---\n\n\u003ca name=\"setEndpoint\"\u003e\u003c/a\u003e\n**`setEndpoint( $endpoint )`** - set request output\n\nAccepts string as parameter, `json` or `xml`, if omitted defaulted to `json`.\nReturns reference to it's self.\n\n```php\n$response = \\GoogleMaps::load('geocoding')\n\t\t-\u003esetEndpoint('json')  // return $this\n\t\t...\n```\n---\n\n\u003ca name=\"getEndpoint\"\u003e\u003c/a\u003e\n**`getEndpoint()`** - get current request output\n\nReturns string.\n\n```php\n$endpoint = \\GoogleMaps::load('geocoding')\n\t\t-\u003esetEndpoint('json')\n\t\t-\u003egetEndpoint();\n\necho $endpoint; // output 'json'\n```\n\n---\n\n\u003ca name=\"setParamByKey\"\u003e\u003c/a\u003e\n**`setParamByKey( $key, $value )`** - set request parameter using key:value pair\n\nAccepts two parameters:\n\n- `key` - body parameter name\n- `value` - body parameter value\n\nDeeply nested array can use 'dot' notation to assign value.\nReturns reference to it's self.\n\n```php\n$endpoint = \\GoogleMaps::load('geocoding')\n   -\u003esetParamByKey('address', 'santa cruz')\n   -\u003esetParamByKey('components.administrative_area', 'TX') //return $this\n    ...\n```\n\n---\n\n\u003ca name=\"setParam\"\u003e\u003c/a\u003e\n**`setParam( $parameters)`** - set all request parameters at once\n\nAccepts array of parameters\nReturns reference to it's self.\n\n```php\n$response = \\GoogleMaps::load('geocoding')\n                -\u003esetParam([\n                   'address'     =\u003e 'santa cruz',\n                   'components'  =\u003e [\n                        'administrative_area'   =\u003e 'TX',\n                        'country'               =\u003e 'US',\n                         ]\n                     ]) // return $this\n...\n```\n\n---\n\n\u003ca name=\"get\"\u003e\u003c/a\u003e\n\n- **`get()`** - perform web service request (irrespectively to request type POST or GET )\n- **`get( $key )`** - accepts string response body key, use 'dot' notation for deeply nested array\n\nThis method is not Available for Routes API.\n\nReturns web service response in the format specified by **`setEndpoint()`** method, if omitted defaulted to `JSON`.\nUse `json_decode()` to convert JSON string into PHP variable. See [Processing Response](https://developers.google.com/maps/documentation/webservices/#Parsing) for more details on parsing returning output.\n\n```php\n$response = \\GoogleMaps::load('geocoding')\n                -\u003esetParamByKey('address', 'santa cruz')\n                -\u003esetParamByKey('components.administrative_area', 'TX')\n                 -\u003eget();\n\nvar_dump( json_decode( $response ) );  // output\n\n/*\n{\\n\n   \"results\" : [\\n\n      {\\n\n         \"address_components\" : [\\n\n            {\\n\n               \"long_name\" : \"277\",\\n\n               \"short_name\" : \"277\",\\n\n               \"types\" : [ \"street_number\" ]\\n\n            },\\n\n            ...\n*/\n```\n\n\n\nExample with `$key` parameter\n\n```php\n$response = \\GoogleMaps::load('geocoding')\n                -\u003esetParamByKey('latlng', '40.714224,-73.961452')\n                 -\u003eget('results.formatted_address');\n\nvar_dump( json_decode( $response ) );  // output\n\n/*\narray:1 [▼\n  \"results\" =\u003e array:9 [▼\n    0 =\u003e array:1 [▼\n      \"formatted_address\" =\u003e \"277 Bedford Ave, Brooklyn, NY 11211, USA\"\n    ]\n    1 =\u003e array:1 [▼\n      \"formatted_address\" =\u003e \"Grand St/Bedford Av, Brooklyn, NY 11211, USA\"\n    ]\n            ...\n*/\n```\n---\n\n\u003ca name=\"fetch\"\u003e\u003c/a\u003e\n\n- **`fetch()`** - only available for Routes API (whith 'routes' or 'routematrix' services)\n\nThis method is ONLY available for Routes API.\nNote: config for routes included **decodePolyline** parameter, default **true**. If **true** it will attempts to decode the `polilyne.encodedPolyline` and add `decodePolyline` parameter to the response.\n\nReturns an **array** web service response or thows an **ErrorException**. \nSee [Request Body](https://developers.google.com/maps/documentation/routes/reference/rest/v2/TopLevel/computeRoutes#request-body) for details.\n\n```php\n$response = \\GoogleMaps::load('routes')\n                -\u003esetParam($reqRoute) // \u003c-- array see config file for all available parameters or Request Body\n                -\u003efetch();\n```\n\n---\n\n\u003ca name=\"isLocationOnEdge\"\u003e\u003c/a\u003e\n**`isLocationOnEdge( $lat, $lng, $tolrance = 0.1 )`** - To determine whether a point falls on or near a polyline, or on or near the edge of a polygon, pass the point, the polyline/polygon, and optionally a tolerance value in degrees.\n\nThis method only available with Google Maps Routes API.\n\nAccepted parameter:\n\n- `$lat` - double latitude\n- `$lng` - double longitude\n- `$tolrance` - double\n\n```php\n$response = \\GoogleMaps::load('routes')\n            -\u003esetParam([\n                        'origin' =\u003e [\n                            'location' =\u003e [\n                                'latLng' =\u003e [\n                                    'latitude' =\u003e 37.419734,\n                                    'longitude' =\u003e -122.0827784,\n                                ],\n                            ],\n                        ],\n                        'destination' =\u003e [\n                            'location' =\u003e [\n                                'latLng' =\u003e [\n                                    'latitude' =\u003e 37.417670,\n                                    'longitude' =\u003e -122.079595,\n                                ],\n                            ],\n                        ],\n                        'travelMode' =\u003e 'DRIVE',\n                        'routingPreference' =\u003e 'TRAFFIC_AWARE',\n                        'computeAlternativeRoutes' =\u003e false,\n                        'routeModifiers' =\u003e [\n                            'avoidTolls' =\u003e false,\n                            'avoidHighways' =\u003e false,\n                            'avoidFerries' =\u003e false,\n                        ],\n                        'languageCode' =\u003e 'en-US',\n                        'units' =\u003e 'IMPERIAL',\n                    ])\n           -\u003eisLocationOnEdge(37.41665,-122.08175);\n\n    dd( $response  );  // true\n```\n\n---\n\n\u003ca name=\"containsLocation\"\u003e\u003c/a\u003e\n**`containsLocation( $lat, $lng )`** -To find whether a given point falls within a polygon.\n\nThis method only available with Google Maps Routes API.\n\nAccepted parameter:\n\n- `$lat` - double latitude\n- `$lng` - double longitude\n\n```php\n$response = \\GoogleMaps::load('routes')\n            -\u003esetParam([\n                        'origin' =\u003e [\n                            'location' =\u003e [\n                                'latLng' =\u003e [\n                                    'latitude' =\u003e 37.419734,\n                                    'longitude' =\u003e -122.0827784,\n                                ],\n                            ],\n                        ],\n                        'destination' =\u003e [\n                            'location' =\u003e [\n                                'latLng' =\u003e [\n                                    'latitude' =\u003e 37.417670,\n                                    'longitude' =\u003e -122.079595,\n                                ],\n                            ],\n                        ],\n                        'travelMode' =\u003e 'DRIVE',\n                        'routingPreference' =\u003e 'TRAFFIC_AWARE',\n                        'computeAlternativeRoutes' =\u003e false,\n                        'routeModifiers' =\u003e [\n                            'avoidTolls' =\u003e false,\n                            'avoidHighways' =\u003e false,\n                            'avoidFerries' =\u003e false,\n                        ],\n                        'languageCode' =\u003e 'en-US',\n                        'units' =\u003e 'IMPERIAL',\n                    ])\n           -\u003econtainsLocation(37.41764,-122.08293);\n\n    dd( $response  );  // true\n```\n\n\n\n\n## Support\n\n[Please open an issue on GitHub](https://github.com/alexpechkarev/google-maps/issues)\n\n## License\n\nCollection of Google Maps API Web Services for Laravel is released under the MIT License. See the bundled\n[LICENSE](https://github.com/alexpechkarev/google-maps/blob/master/LICENSE)\nfile for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexpechkarev%2Fgoogle-maps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexpechkarev%2Fgoogle-maps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexpechkarev%2Fgoogle-maps/lists"}