elrihor's avatar

Geocoder Laravel in local environment

Hello,

I'm building an map application, where a user can create an entry by entering an address. The coordinates for this address should be fetch in a job from the Mapbox Geocoding API. For the geocoding I'm using the Laravel Package of Geocoder PHP with the Mapbox provider. As the http client I'm using Guzzle.

Usually it should be a simple task, but for some reason im allways getting an empty answer. The things i checked so far are:

  • Using the correct API key ✔️
  • Logged the request url within the package and tried it directly in the browser ✔️

During my research for similiar problems I found something in the Geocoder PHP docs on how you should configure your http client.

Because you cannot configure the http client with Geocoder Laravel I searched for the part where the adapter is initialized and hardocded the config to not use credentials and it worked.

if ($adapter) {
 if ($this->requiresReader($provider)) {
    $adapter = new $adapter($this->getReader());
  } else {
    $adapter = new $adapter([
      "verify" => false
    ]);
  }
  array_unshift($arguments, $adapter);
}

File: ProviderAndDumpAggregator.php

Another way to fix this is to change the request url from https to http.

const GEOCODE_ENDPOINT_URL_SSL = 'http://api.mapbox.com/geocoding/v5/%s/%s.json';

Mapbox.php

Based an these two possibly fixes I assumed that my local enivornment was the problem. At first I used php artisan serve and switched to symfony serve which can provid a ssl certificate to access localhost via https.

Unfortunatly this didn't solve the problem. I'm very certain that the problem has something to do with SSL, but I cannot think of anything other than servering my app locally over https. I'm not considering the fixes that worked, becouse i have to alter the package files.

0 likes
1 reply
elrihor's avatar
elrihor
OP
Best Answer
Level 1

Laravel's error message is

[2023-04-11 07:38:46] local.ALERT: Provider "{providerName}" could not geocode address: "{address}". {"exception":"[object] (GuzzleHttp\Exception\RequestException(code: 0): cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://api.mapbox.com/geocoding/v5/mapbox.places/16-18%2C%20Argyle%20Street%2C%20Camden%2C%20London%2C%20WC1H%208EG%2C%20United%20Kingdom.json?types=address&limit=5&access_token=/*ACCESS TOKEN*/ at C:\...\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:211)

The solution was to use a ssl certificate with php: https://docs.boltcms.io/5.0/howto/curl-ca-certificates

Please or to participate in this conversation.