Geocoder icon indicating copy to clipboard operation
Geocoder copied to clipboard

Algolia provider returning empty results.

Open mikebronner opened this issue 4 years ago • 7 comments

Asking on behalf of @tanthammar, who posted this issue here: https://github.com/geocoder-php/GeocoderLaravel/issues/163


General Information

GeocoderLaravel Version: ^4.2 Laravel Version: 6 PHP Version: 7.3.8 Operating System and Version: OSX 10.14.6

Issue Description

I do understand that this might not be the proper place to ask, but I was hoping that someone might have a solution. :)

Unable to get this to work with the Algolia geocoder provider No errors, but always an empty collection returned.

(I have it working with the Nominatim and GoogleMaps)

Steps to Replicate

composer require geocoder-php/algolia-places-provider^0.1.1

in config/geocoder.php

'providers' => [
        Chain::class => [
            AlgoliaPlaces::class => [
                'my-api-key',
                'my-app-id'
            ],
            Nominatim::class => [
                'https://nominatim.openstreetmap.org',
                'en'
            ],
            GoogleMaps::class => [
                env('GOOGLE_MAPS_LOCALE', 'en-US'),
                env('GOOGLE_MAPS_API_KEY'),
            ],
            GeoPlugin::class  => [],
        ],
    ],

Stack Trace

[if an error is occuring, provide the complete stack trace here]

mikebronner avatar Oct 15 '19 17:10 mikebronner

I've just double checked by running the test suite and it seems to be working correctly.

Can you share the code you are using to get the result, and the address you are geocoding?

Thanks

atymic avatar Oct 15 '19 23:10 atymic

Hello, thank you for your reply.

I got it working, but the returned search result are a bit confusing.

Strange error. This works in Nominatim but returns error from this driver.

>>> $addresses = app('geocoder')->geocode('113 46, Stockholm')->dump('geojson');
TypeError: Return value of Geocoder/Dumper/GeoJson::dump() must be of the type string, bool returned
>>> 

This however works

$addresses = app('geocoder')->geocode('113 45, Stockholm')->dump('geojson');
>>> multiple results

Inconsistent results: Via geocoder

>>> $addresses = app('geocoder')->geocode('Idungatan 7c, 113 45, Stockholm')->dump('geojson');
=> Illuminate\Support\Collection {#3489
     all: [],
   }

Via the search field in Algolia app, places, dashboard I do get a suggestion, even though it is not the correct lat/long. (It suggests the city "Stockholm" in Sweden) Suppose this is not this repos fault :). I was expecting the same result or any result.

{
  "query": "Idungatan 7c, Stockholm",
  "suggestion": {
    "name": "Stockholm",
    "country": "Sverige",
    "countryCode": "se",
    "type": "city",
    "latlng": {
      "lat": 59.3326,
      "lng": 18.0649
    },
    "postcode": "100 05",
    "highlight": {
      "name": "<em>Stockholm</em>",
      "country": "Sverige"
    },
    "value": "Stockholm, Sverige"
  }
}

tanthammar avatar Oct 22 '19 15:10 tanthammar

Hmm. I've double checked that the code is querying correctly without any filters and I still get no results.

Could this be due to https://www.algolia.com/doc/api-reference/api-parameters/aroundLatLngViaIP/?

atymic avatar Oct 24 '19 00:10 atymic

I am not sure. This is all very new to me. Did you look into the first error?

tanthammar avatar Oct 26 '19 09:10 tanthammar

@tanthammar

I'm guessing it's related to that. Can you try direct with that param disabled?

In regards to the first error, could you please add dd(json_last_error()) after the geocode call?

I'm pretty sure something is going borked with the array which causes the json encode to fail.

Thanks!

atymic avatar Nov 01 '19 23:11 atymic

@tanthammar

Were you able to do the above?

atymic avatar Nov 21 '19 04:11 atymic

@tanthammar

Were you able to do the above?

atymic avatar Jan 07 '20 05:01 atymic