Library for retrieving coordinates for addresses and vice versa
GeoFetcher has two providers implemented:
composer require devpack/geo-fetcher
- 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
]);
Paramter is array of addreses and GeoFetcher always return array
// Feth coordinates from adress - parameter must be array
$result = $geoFetcher->fetchCoordinates(
['Kielce, Mickiewicza 1'],
);
array:1 [
0 => array:2 [
"lat" => 50.8676012
"lng" => 20.6329186
]
]
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,
],
]);
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
]
]