flibidi67 / open-meteo-geocoding
PHP SDK,用于使用 Open Meteo Geocoding API
1.0.0
2023-03-29 08:23 UTC
Requires
- php: >=8
- ext-curl: *
This package is not auto-updated.
Last update: 2024-09-26 13:37:58 UTC
README
Open-Meteo 与国家气象服务合作,提供 11 到 2 公里的分辨率的开源数据。我们的高性能 API 会为您的位置选择最佳天气模型,并提供简单的 JSON API 的数据。
API 对开源开发者和非商业用途免费,无需任何 API 密钥。您可以直接将其嵌入到您的应用程序中。
官方文档可在此处找到。
安装
您可以通过 composer 安装此包
composer require flibidi67/open-meteo-geocoding
用法
原生 PHP
require_once('/path/to/vendor/flibidi67/open-meteo-geocoding/src/Service/GeocodingService');
use Flibidi67\OpenMeteoGeocoding\Service\GeocodingService;
$service = new GeocodingService();
Symfony
如果您想使用 DependencyInjection,您必须在您的 config/services.yaml
中添加以下内容
services:
# your other configuration
Flibidi67\OpenMeteoGeocoding\Service\GeocodingService:
autowire: true
然后您可以像这样使用它
use Flibidi67\OpenMeteoGeocoding\Service\GeocodingService;
public function myFunction(GeocodingService $geocodingService) {
$geocodingService->get('Stras');
}
// or
public function myFunction2() {
$geocodingService = new GeocodingService();
$geocodingService->get('Stras');
}
可用的服务方法
以下是所有可用的服务方法
setLanguage
,设置语言,接受的值是en
、de
、fr
、es
、it
、pt
、ru
、tr
和hi
,默认为en
。setFormat
,设置格式,坦白说,没什么用,因为目前只支持json
。setCount
,设置要检索的结果数量(最少 1,最多 100),默认10
。setName
,设置搜索字段,必须至少有 3 个字符。setCurlCheckSSLCertificate
,禁用 curl SSL 验证(不推荐,但以防万一),默认true
。get
,检索结果,您可以在调用此方法时提供搜索字段,见上面的示例
如果您手动实例化服务,您可以提供设置数组以避免使用 set 方法,如下所示
$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
);