Git Product home page Git Product logo

php-nominatim's Introduction

Wrapper Nominatim API

Latest Stable Version Build Status Scrutinizer Code Quality Total Downloads MIT licensed

SensioLabsInsight

A simple interface to OSM Nominatim.

See Nominatim documentation for info on the service.

Installation

Install the package through composer:

composer require maxh/php-nominatim

Make sure, that you include the composer autoloader somewhere in your codebase.

Basic usage

Create a new instance of Nominatim.

use maxh\Nominatim\Nominatim;

$url = "http://nominatim.openstreetmap.org/";
$nominatim = new Nominatim($url);

Searching by query :

$search = $nominatim->newSearch();
$search->query('HelloWorld');

$nominatim->find($search);

Or break it down by address :

$search = $nominatim->newSearch()
            ->country('France')
            ->city('Bayonne')
            ->postalCode('64100')
            ->polygon('geojson')    //or 'kml', 'svg' and 'text'
            ->addressDetails();

$result = $nominatim->find($search);

Or do a reverse query :

$reverse = $nominatim->newReverse()
            ->latlon(43.4843941, -1.4960842);

$result = $nominatim->find($reverse);

Or do a lookup query :

$lookup = $nominatim->newLookup()
            ->format('xml')
            ->osmIds('R146656,W104393803,N240109189')
            ->nameDetails(true);

$result = $nominatim->find($lookup);

Or do a details query (by place_id):

$details = $nominatim->newDetails()
            ->placeId(1234)
            ->polygon('geojson');

$result = $nominatim->find($details);

Or do a details query (by osm type and osm id):

$details = $nominatim->newDetails()
            ->osmType('R')
            ->osmId(1234)
            ->polygon('geojson');

$result = $nominatim->find($details);

By default, the output format of the request is json and the wrapper return a array of results. It can be also xml, but the wrapper return a object SimpleXMLElement

How to override request header ?

There are two possibilities :

  1. By Nominatim instance, for all request :
$nominatim = new Nominatim($url, [
    'verify' => false
]);
  1. By find method, for a request :
$result = $nominatim->find($lookup, [
    'verify' => false
]);

How to customize HTTP client configuration ?

You can inject your own HTTP client with your specific configuration. For instance, you can edit user-agent and timeout for all your requests

<?php
use maxh\Nominatim\Nominatim;
use GuzzleHttp\Client;

$url = "http://nominatim.openstreetmap.org/";
$defaultHeader = [
    'verify' => false,
    'headers', array('User-Agent' => 'api_client')
];

$client = new Client([
    'base_uri'           => $url,
    'timeout'            => 30,
    'connection_timeout' => 5,
]);

$nominatim = new Nominatim($url, $defaultHeader, $client);

Note

This projet was inpired by the Opendi/nominatim project with more features like reverse query, support of the xml format, customize HTTP client and more on which i work.

Recall Usage Policy Nominatim

If you use the service : http://nominatim.openstreetmap.org/, please see Nominatim usage policy.

php-nominatim's People

Contributors

gitter-badger avatar maxhelias avatar miskith avatar reblack avatar scrutinizer-auto-fixer avatar straschek-io avatar xemlock avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

php-nominatim's Issues

Add parameter "bounded" to Nominatim search

The Nominatim search api has a "bounded" parameter which takes a value of "0 or 1" to make the search bounded to the viewBox (this parameter already exists in the library); it could be great to add it.

Naming of countrycodes parameter is wrong

Bug

The parameter passed to nominatim for limiting the search scope to a country in https://github.com/maxhelias/php-nominatim/blob/master/src/Search.php#L164 is wrong.

It should be named countrycodes, not countrycode.

Version and provider

Current master, search provider

Reproduction

Compare:
https://nominatim.openstreetmap.org/search?format=json&q=41460&limit=1&countrycode=de
(leads to same result as https://nominatim.openstreetmap.org/search?format=json&q=41460&limit=1&countrycodes=se)
vs.
https://nominatim.openstreetmap.org/search?format=json&q=41460&limit=1&countrycodes=de

about updating nominatim...

Bug, feature or question?

Is this a bug, a feature request or a question?

Give us a short description.

Version and provider

What version of PHP-Nominatim does this relates to?

Is this an issue with a provider? If yes, which one? (Search, Reverse, Lookup)

Reproduction

How can we replicate this issue?

call to undefined function guzzlehttp\psr7\build_query()

Guzzle ^ 7.3 incompatibility

The library is not compatible with ^ 7.3 since the guzzlehttp\psr7\build_query () method has been deprecated

Solution found

In the Nominatim file on line 189 it is required to replace all calls to guzzlehttp\psr7\build_query() by http_build_query

// Old
$query = \GuzzleHttp\Psr7\build_query($nRequest->getQuery(), PHP_QUERY_RFC1738);

// New
$query = http_build_query($nRequest->getQuery());`

[Question] Class 'Client' not found

Question

composer.json

     "require": {
        "php": "^7.4",
        "guzzlehttp/guzzle": "^7.0",
        "maxh/php-nominatim": "^2.3"
}

karte.php

use maxh\Nominatim\Nominatim;
    $adresse        = [
        'strasse'   =>  $strasseXml,
        'ort'       =>  $datensatz['Ort'],
        'plz'       =>  $datensatz['PLZ']        
    ];

    $url = "http://nominatim.openstreetmap.org/";
    $defaultHeader = [
        'verify' => false,
        'headers', array('User-Agent' => 'api_client')
    ];

    $client = new Client([
        'base_uri'           => $url,
        'timeout'            => 30,
        'connection_timeout' => 5,
    ]);

    $nominatim = new Nominatim($url, $defaultHeader, $client);
    $search = $nominatim->newSearch()
        ->street($adresse['strasse'])
        ->city($adresse['ort'])
        ->postalCode($adresse['plz'])
        ->country('Germany')
        ->addressDetails();
    $nominatim->find($search);
    
    dump($nominatim->find($search));

Fatal error: Uncaught Error: Class 'Client' not found in C:\xampp\htdocs\familienfreunde\familienkatalog\templates\details\karte.php:34 Stack trace: #0 C:\xampp\htdocs\familienfreunde\familienkatalog\public\99.php(46): require_once() #1 {main} thrown in C:\xampp\htdocs\familienfreunde\familienkatalog\templates\details\karte.php on line 34

[Feature] Use client inteface or Psr Client interface

Hi

In your \maxh\Nominatim\Nominatim constructor, you accept a custom Guzzle Client instance, which is really fine. But would it perhaps not be prudent to accept \GuzzleHttp\ClientInterface or \Psr\Http\Client\ClientInterface as argument?
If so, the your component's flexibility will increase, by allowing developers to provide custom http client implementations.

This feature request can be considered somewhat breaking. So, if you accept it, then it should be for your next major version.

Invalid class names in phpdoc blocks

Bug, feature or question?

Is this a bug, a feature request or a question?

Bug.

Give us a short description.

Class names present in @param and @return fields inside phpdoc blocks are missing prefixing slash, which makes them relative to the namespace (according to the phpdocumentor rules). In result they are invalid and break auto-completion in IDEs.

Version and provider

What version of PHP-Nominatim does this relates to?

Any.

Is this an issue with a provider? If yes, which one? (Search, Reverse, Lookup)

All.

Reproduction

How can we replicate this issue?

The bug already manifested itself in the documentation. Look at class names auto-generated by phpdoc - there are obviously invalid ones like \maxh\Nominatim\Guzzle\Client (here).

You can also see it in IDEs - class names are resolved to non-existent ones:

phpstorm-nominatim

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.