Skip to content

kosmala007/geo-fetcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Geo Fetcher

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
    ]
]

About

Library for retrieving coordinates for addresses and vice versa

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages