Geocoding reverse problem

Foxchip5 years ago

Hello,

since several days, my reverse geocoding won't work
I have this error in traccar log:

WARN: Geocoder network error - HTTP 403 Forbidden - ForbiddenException (... < JsonGeocoder:107 < ServerResource:57 < ...)

I tried with several geocoder provider found on documentation ans always the same error
Could you help me?

Best regards

Jerome

Norm5 years ago

I am getting a similar error.

Here is where is started.

2019-10-25 10:39:15  WARN: Geocoding failed - Connection timed out (Connection timed out) - ConnectException (...)

Then everyone after that is:

2019-10-25 11:14:43  WARN: Geocoding failed - HTTP 403 Forbidden - ForbiddenException (...)
dagobar5 years ago

Hello.
I had the same problem with free Nominatim provider. I presume you need to change user_agent according to their rules but I did not find where to change this setting in traccar.
I switched to locationiq.com also a free service with max 10000 request/month and it's working.
Please write here if you manage to change user_agent and it's working (or not).

IoSonoPiero5 years ago

Hello,
I've temporary solved using OpenCage, but it seems don't offer the same precision as Nominatim. I mean, I got only the name of a macroregion.

Foxchip5 years ago

Yes solved also with OpenCage

I get the same error with Nominatim and locationiq.

jay5 years ago

previously server should show address with Nominatim and locationiq. But these 2 weeks know its not showing address. Any idea as to why. thanks in advance.

dagobar5 years ago

It's working for my server with free locationiq service. Please check your configuration.

jay5 years ago

Can you post your traccar.xml config please

jay5 years ago

this is my geocoder settings

    <entry key='geocoder.enable'>true</entry>
    <entry key='geocoder.type'>nominatim</entry>
    <entry key='geocoder.key'>api_key</entry>
metacreo5 years ago

I think is not geocoder provider bug.

    <entry key='geocoder.enable'>true</entry>
    <entry key='geocoder.type'>nominatim</entry>
    <entry key='geocoder.url'>https://nominatim.openstreetmap.org/reverse</entry>

In server console I try curl https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=54.XXXX&lon=25.XXXX and go OK response.
Need debug traccar

metacreo5 years ago

I think is not geocoder provider bug or restriction.

    <entry key='geocoder.enable'>true</entry>
    <entry key='geocoder.type'>nominatim</entry>
    <entry key='geocoder.url'>https://nominatim.openstreetmap.org/reverse</entry>

On click "Show address" error in log WARN: Geocoder network error - HTTP 403 Forbidden - ForbiddenException (... < JsonGeocoder:107 < ServerResource:57 < ...)

In server console:

PING nominatim.openstreetmap.org (130.117.76.9): 56 data bytes
64 bytes from 130.117.76.9: icmp_seq=0 ttl=56 time=33.488 ms
64 bytes from 130.117.76.9: icmp_seq=1 ttl=56 time=33.478 ms

connection ok

curl 'https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=54.XXXX&lon=25.XXXX'

got OK response all string with city, street, etc...
Need debug traccar

metacreo5 years ago

https://github.com/traccar/traccar/issues/4446

nominatim need user-agent in request.

console: curl -A "" 'https://nominatim.openstreetmap.org/reverse?format=json&lat=54.99991&lon=25.9999&addressdetails=1'

Response: Access blocked

console: curl -A "mozilla" 'https://nominatim.openstreetmap.org/reverse?format=json&lat=54.99991&lon=25.9999&addressdetails=1'

Response: OK

metacreo5 years ago

Solution traccar - nominatim:

Requirements: Apache, php, php-curl.

myhostname.com -> your_hostname

Since Apache and PHP is running on my server, I created something like a gasket (php script) between the traccar and nominatim, thanks to which, the request is supplemented by an user-agent.

I have a Secure Connection on apache virtualhost with proxy to traccar.
So that the executed php script does not fall under the proxy rules of the virtualhost, I added in virtualhost config "ProxyPass /tools/ !" and created "tools" directory in DocumentRoot.
My virtualhost full config:

<VirtualHost *:80>
    ServerName track.myhostname.com
    Redirect / https://track.myhostname.com
</VirtualHost>
<VirtualHost *:443>
    ServerAdmin admin@myhostname.com
    ServerName track.myhostname.com
    DocumentRoot /usr/local/www/traccar/www
    SSLEngine on
    <Directory /usr/local/www/traccar/www>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    ProxyPass /tools/ !
    ProxyPass /icons/ !
    ProxyPass /api/socket ws://localhost:8082/api/socket
    ProxyPassReverse /api/socket ws://localhost:8082/api/socket
    ProxyPass / http://localhost:8082/
    ProxyPassReverse / http://localhost:8082/
    LogLevel warn
    ErrorLog /usr/local/www/traccar/logs/error.log
    CustomLog /usr/local/www/traccar/logs/access.log combined
</VirtualHost>

Inside "tools" directory I placed my php script (reverse.php) and .htaccess files.

htaccess file content (change YOUR_SERVER_REAL_OUTSIDE_IP and myhostname.com):

Deny from all
Allow from localhost
Allow from 127.0.0.1
Allow from myhostname.com
Allow from YOUR_SERVER_REAL_OUTSIDE_IP
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.*) $1.php [L]

reverse.php script content:

<?php
$user_agent = 'traccar'; // specify your user-agent
$nominatim_url = 'https://nominatim.openstreetmap.org/reverse'; 
$error = array();
if ($_SERVER['REMOTE_ADDR'] !== $_SERVER['SERVER_ADDR']) {
    $error[] = 'only local query allowed';
}
if (!isset($_GET) || empty($_GET)) {
    $error[] = 'no parameters';
} elseif (!isset($_GET['format']) || !isset($_GET['lat']) || !isset($_GET['lon']) || !isset($_GET['zoom']) || !isset($_GET['addressdetails'])) {
    $error[] = 'not complete parameters';
} elseif ($_GET['format'] !== 'json' || !is_numeric($_GET['lat']) || !is_numeric($_GET['lon']) || !is_numeric($_GET['zoom']) || !is_numeric($_GET['addressdetails'])) {
    $error[] = 'invalid parameters';
} else {
    header('Content-Type: application/json; charset=utf-8');
    $query_data = array(
        'format'         => $_GET['format'],
        'lat'            => $_GET['lat'],
        'lon'            => $_GET['lon'],
        'zoom'           => $_GET['zoom'],
        'addressdetails' => $_GET['addressdetails']
    );
    $query = http_build_query($query_data);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $nominatim_url.'?'.$query);
    $response = curl_exec($ch);
    $status_code = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    if ($status_code !== 200) {
        $error[] = 'no valid response from nominatim';
    }
}
if ($error) {
    header('Content-Type: text/html; charset=utf-8');
    echo implode('<br>', $error);
} else {
    header('Content-Type: application/json; charset=utf-8');
    echo $response;
}
?>

in traccar config (traccar.xml) change:

<entry key='geocoder.url'>https://nominatim.openstreetmap.org/reverse</entry>

to (do not forget to change myhostname.com):

<entry key='geocoder.url'>https://track.myhostname.com/tools/reverse</entry>

restart your services, should work :)

Macan5 years ago

Hi ppl,
I contacted locationIQ support and here is the answer :
"Thanks for writing in!

Our API will respond with 403 code for requests which come from unauthorized domains. We noticed that you've added HTTP referrer restrictions to your access token(http://1.1.1.1). We recommend you, adding domain URL patterns to HTTP referrer patterns list instead of IP Addresses"

So if you use domain name it should be fine but with IP there is an error.