plutuss/laravel-geonames-api

Laravel Geonames API 包提供了一种简单的方法,将 Geonames API 集成到您的 Laravel 应用程序中。此包使开发者能够轻松地与 Geonames API 交互,以检索诸如城市、国家、坐标、时区和其它基于位置的信息等地理数据。

0.1.3 2024-07-13 14:33 UTC

This package is auto-updated.

Last update: 2024-09-16 21:20:53 UTC


README

Laravel

注意

The Laravel Geonames API package provides an easy way to integrate the Geonames API into your Laravel application. This package enables developers to effortlessly interact with the Geonames API to retrieve geographic data such as cities, countries, coordinates, time zones, and other location-based information.

  • 主要特性
  1. Geonames API 请求:发送请求和处理 Geonames API 响应的简单方法。
  2. 支持多种查询类型:支持所有主要查询类型,包括名称搜索、反向地理编码等。
  3. 配置:通过配置文件轻松设置 API 凭证和其他参数。
  4. Laravel 兼容性:完全集成 Laravel 生态系统,包括支持 Service Providers 和 Facades。
 composer require plutuss/geo-names-laravel
php artisan vendor:publish --provider="Plutuss\GeoNames\Providers\GeoNamesServiceProvider"
#  .env
GEO_NAMES_USERNAME=user_name

使用 Facade GeoName

        $response = GeoName::postalCodeSearchJSONFromName('city_name');

        $response = GeoName::setPostalCode(6600)
            ->setCountryCode('CH')
            ->postalCodeSearchJSONFromName('city_name');
            
          // OR
      
        $response = GeoName::setOption([
            'country' => 'CH',
        ])->postalCodeSearchJSONFromName('city_name');
        $response = GeoName::postalCodeSearchJSONFromPostCode(6600);

        $response = GeoName::setCountryCode('CH')
            ->postalCodeSearchJSONFromPostCode(6600);
            
          // OR

        $response = GeoName::setOption([
            'country' => 'CH',
        ])->postalCodeSearchJSONFromPostCode('6600');
     setCountryCode(string $countryCode): static;
    
     setPostalCode(int $value): static;

     setPostalCodeStartsWith(string $value): static;
 
     setPlaceName(string $value): static;

     setPlaceNameStartsWith(string $value): static;

     setCountry(string $value): static;

     setCountryBias(string $value): static;

     setMaxRows(int $value): static;
  
     setStyle(string $value): static;

     setOperator(string $value): static;

     setCharset(string $value): static;

     setIsReduced(bool $value): static;
   
     setEast(float $value): static;
   
     setWest(float $value): static;

     setNorth(float $value): static;

     setSouth(float $value): static;
 
     setLatitude(string $value): static;

     setLongitude(string $value): static;
 
     setRadius(int $value): static;
     setOption(array $params): static;
     searchJSON(string $country): JsonResponse|array|Collection;

     postalCodeSearchJSONFromPostCode(int $postalCode, int $radius = 5, int $maxRows = 10): JsonResponse|array|Collection;

     postalCodeSearchJSONFromName(string $name, int $radius = 5, int $maxRows = 10): JsonResponse|array|Collection;

     findNearbyPostalCodes(int $lat, int $lng): JsonResponse|array|Collection;

     postalCodeCountryInfo(): JsonResponse|array|Collection;

     findNearbyJSON(int $lat, int $lng): JsonResponse|array|Collection;

响应

     latitude(): mixed;

     getCollectionData(): Collection;

     getArrayData(): array;

     longitude(): mixed;

     placeName(): mixed;

     postalCode(): mixed;

     countryCode(): mixed;

     region(): mixed;

     land(): mixed;

    // The getNestedValue() method retrieves a value
    // from a deeply nested array using "dot" notation
    // $response->getNestedValue('key.array')
     getNestedValue($path, $default = null): mixed;