devpack / geo-fetcher
Library for retrieving coordinates for addresses and vice versa
v1.0.0
2020-04-12 12:30 UTC
Requires
- guzzlehttp/guzzle: ^6.5
- symfony/property-access: ^4.4
Requires (Dev)
- edgedesign/phpqa: ^1.23
- friendsofphp/php-cs-fixer: ^2.16
- jakub-onderka/php-parallel-lint: ^1.0
- phpunit/phpunit: ^8.5
- sensiolabs/security-checker: ^6.0
- symfony/var-dumper: ^4.4
- vimeo/psalm: ^3.10
This package is auto-updated.
Last update: 2025-03-12 23:51:45 UTC
README
Library for retrieving coordinates for addresses and vice versa
GeoFetcher has two providers implemented:
How it use?
Instalation
composer require devpack/geo-fetcher
Initialize GeoFetcher
Available providers
- GoogleMaps
- OpenStreetMaps
<?php use DevPack\GeoFetcher\GeoFetcher; $geoFetcher = new GeoFetcher([ 'apiKey' => 'yourApiKey', // required if You use GoogleMaps 'provider' => 'GoogleMaps', // one from available providers 'lang' => 'pl', // code ISO 639-1 ]);
Fetch Coordinates from addres string
Paramter is array of addreses and GeoFetcher always return array
// Feth coordinates from adress - parameter must be array $result = $geoFetcher->fetchCoordinates( ['Kielce, Mickiewicza 1'], );
Example response
array:1 [ 0 => array:2 [ "lat" => 50.8676012 "lng" => 20.6329186 ] ]
Fetch address details from coordinates
Paramter is array of addreses and GeoFetcher always return array
// Fetch address from coordinates - parameter must be array $result = $geoFetcher->fetchAddresses([ [ 'lat' => 50.869023, 'lng' => 20.634476, ], ]);
Example response
array:1 [ 0 => array:8 [ "country" => "Polska" "administrative_area_level_1" => "województwo świętokrzyskie" "locality" => "Kielce" "route" => "Henryka Sienkiewicza" "postal_code" => "25-350" "street_number" => "3" "lat" => 50.869023 "lng" => 20.634476 ] ]