flibidi67 / open-meteo-geocoding
PHP SDK to use Open Meteo Geocoding API
Requires
- php: >=8
- ext-curl: *
This package is not auto-updated.
Last update: 2024-05-23 12:14:57 UTC
README
Open-Meteo collaborates with National Weather Services providing Open Data with 11 to 2 km resolution. Our high performance APIs select the best weather model for your location and provide data as a simple JSON API.
APIs are free without any API key for open-source developers and non-commercial use. You can embed them directly into your app.
Official documentation is available here.
Installation
You can install the package via composer:
composer require flibidi67/open-meteo-geocoding
Usage
Native PHP
require_once('/path/to/vendor/flibidi67/open-meteo-geocoding/src/Service/GeocodingService');
use Flibidi67\OpenMeteoGeocoding\Service\GeocodingService;
$service = new GeocodingService();
Symfony
If you want to use DependencyInjection, you have to add this to your config/services.yaml
:
services:
# your other configuration
Flibidi67\OpenMeteoGeocoding\Service\GeocodingService:
autowire: true
Then you can use it like that :
use Flibidi67\OpenMeteoGeocoding\Service\GeocodingService;
public function myFunction(GeocodingService $geocodingService) {
$geocodingService->get('Stras');
}
// or
public function myFunction2() {
$geocodingService = new GeocodingService();
$geocodingService->get('Stras');
}
Available service's methods
Here are all the available service's methods :
setLanguage
, to set the language, accepted values areen
,de
,fr
,es
,it
,pt
,ru
,tr
andhi
, by defaulten
.setFormat
, to set the format, to be honest, useless because onlyjson
is currently supportedsetCount
, to set how much results do you want to retrieve (min 1, max 100), by default10
.setName
, to set the search field, must be at least 3 characters.setCurlCheckSSLCertificate
, to disable curl SSL verification (not recommended, but just in case), by defaulttrue
get
, retrieve the results, you can give the search field when calling this method, see example above
If you are manually instanciate the service, you can give an array of settings to avoid you using the set methods, like this :
$geocodingService = new GeocodingService(
'language' => 'fr',
'name' => 'Stra',
'format' => 'json',
'count' => 42,
'curlCheckSSLCertificate' => false
);
// or just some of them
$geocodingService = new GeocodingService(
'language' => 'fr',
'count' => 42
);