This package is abandoned and no longer maintained. No replacement package was suggested.

OpenStreetMap API Integration

0.2.6 2021-07-16 17:23 UTC

This package is not auto-updated.

Last update: 2024-03-09 06:18:24 UTC


README

OpenStreetMap API Integration

Basic Usage

Find nodes in Germany bounding box: NE 55.05814, 15.04205 SW 47.27021, 5.86624

$south = 47.27021;
$west = 5.86624;
$north = 55.05814;
$east = 15.04205;

// create bounding box
$bBox = new \KageNoNeko\OSM\BoundingBox($south, $west, $north, $east);

// slice to lesser boxes to reduce memory usage
$slices = $bBox->slices(4, 4);

// create connection to Overpass API source
$osm = new \KageNoNeko\OSM\OverpassConnection(['interpreter' => 'http://overpass-api.de/api/interpreter']);

// build query, like we usually do with Database queries
$q = $osm->element('node')
    ->whereTag('aeroway', 'aerodrome')
    ->verbosity('meta')
    ->asJson();

$nodes = [];
foreach ($slices as $slice) {
    //add constraint by boundary box of each slice and get result
    $response = $q->whereInBBox($slice)->get();
    $data = json_decode($response->getBody()->getContents());
    $nodes = array_merge($nodes, $data->elements);
}