geocoder-php / GeocoderLaravel

Geocoder service provider for Laravel
http://geocoder-php.org/GeocoderLaravel/
MIT License
706 stars 102 forks source link

Receiving an Empty Collection #104

Closed StanBarrows closed 7 years ago

StanBarrows commented 7 years ago

General Information

GeocoderLaravel Version: ^4.0 Laravel Version: 5.5.* PHP Version:>=7.0.0 Operating System and Version: Mac with Laravel Valet

Issue Description

I always receiving an Empty Collection.

`Collection {#363 ▼

items: []

}`

Steps to Replicate

use Geocoder\Laravel\Facades\Geocoder;

$result = Geocoder::geocode('Los Angeles, CA')->get();

dd($result);

Google Place API Key is provided, Any suggestions?

mikebronner commented 7 years ago

What version of Mac are you on?

StanBarrows commented 7 years ago

hi Mike, I’m on Sierra and the newest Version of Laravel Valet. I’m try the code on my webserver later this day.

mikebronner commented 7 years ago

Yea, Sierra has/had? a problem with OpenSSL, so it didn't complete the request. If you run it in Homestead it should work (and of course on your server as well). This works fine under High Sierra, I would recommend upgrading if you have no other issues with High Sierra.

StanBarrows commented 7 years ago

@mikebronner

hey, mike. I tried the same on my web server. But unfortunately with the same results. Just an empty collection.

Empty Colleciton

GeoCode Method - Image Code

Geocoder::geocode('Los Angeles, CA')->get();

Same results with the reverse method. $result = Geocoder::reverse(43.882587,-103.454067)->get();

Maybe i'm missing something out of the configuration. What I'm doing atm:

  1. Pull in the Composer package
  2. Check the ServiceProvider and Facade in the config app.php File
  3. Provide an Google Place API Key in the env file.
  4. Clear Caches and composer dump-autoloads
  5. Run above metioned the code

Cheers, Stan

mikebronner commented 7 years ago

What is your server OS and version?

StanBarrows commented 7 years ago

@mikebronner - Its an Ubuntu 16.04.1 LTS

StanBarrows commented 7 years ago

@mikebronner Maybe i'm missing out something else, because when i remove the API KEY in the env file i'm getting the same result.

What I'm doing atm:

  1. Pull in the Composer package
  2. Check the ServiceProvider and Facade in the config app.php File
  3. Provide an Google Place API Key in the env file.
  4. Clear Caches and composer dump-autoloads
  5. Run above metioned the code
mikebronner commented 7 years ago

Did you follow step 5 in the 0.x to 1.0 upgrade notes? Try using app('geocoder') instead of the facade. I believe the facade was removed a while back.

StanBarrows commented 7 years ago

Hi Mike, yes I'm not using a previous version of your package but also tried to run it directly with the provided command:

app('geocoder')->geocode('Los Angeles, CA')->get();

Unfortunately the same result.

StanBarrows commented 7 years ago

@mikebronner

app('geocoder')->geocode('8.8.8.8')->get();This command worked.

`Collection {#362 ▼

items: array:1 [▼

0 => Address {#363 ▼
  -coordinates: Coordinates {#364 ▼
    -latitude: 37.386
    -longitude: -122.0838
  }
  -bounds: null
  -streetNumber: null
  -streetName: null
  -subLocality: null
  -locality: "Mountain View"
  -postalCode: null
  -adminLevels: AdminLevelCollection {#365 ▶}
  -country: Country {#367 ▶}
  -timezone: null
  -providedBy: "geo_plugin"
}

] }`

But it's the only one from the provided commands.

mikebronner commented 7 years ago

Have you tried them all on your server? The others probably won't work on Sierra, like I mentioned earlier. It works perfectly in High Sierra:


php artisan tinker
Psy Shell v0.8.11 (PHP 7.1.9 — cli) by Justin Hileman
>>> dd(app('geocoder')->geocode('Los Angeles, CA')->get());
Illuminate\Support\Collection {#914
  #items: array:1 [
    0 => Geocoder\Provider\GoogleMaps\Model\GoogleAddress {#903
      -id: "ChIJE9on3F3HwoAR9AhGJW_fL-I"
      -locationType: "APPROXIMATE"
      -resultType: array:2 [
        0 => "locality"
        1 => "political"
      ]
      -formattedAddress: "Los Angeles, CA, USA"
      -streetAddress: null
      -intersection: null
      -political: "United States"
      -colloquialArea: null
      -ward: null
      -neighborhood: null
      -premise: null
      -subpremise: null
      -naturalFeature: null
      -airport: null
      -park: null
      -pointOfInterest: null
      -establishment: null
      -subLocalityLevels: Geocoder\Model\AdminLevelCollection {#905
        -adminLevels: []
      }
      -coordinates: Geocoder\Model\Coordinates {#917
        -latitude: 34.0522342
        -longitude: -118.2436849
      }
      -bounds: Geocoder\Model\Bounds {#918
        -south: 33.7036519
        -west: -118.6681759
        -north: 34.3373061
        -east: -118.1552891
      }
      -streetNumber: null
      -streetName: null
      -subLocality: null
      -locality: "Los Angeles"
      -postalCode: null
      -adminLevels: Geocoder\Model\AdminLevelCollection {#919
        -adminLevels: array:2 [
          1 => Geocoder\Model\AdminLevel {#920
            -level: 1
            -name: "California"
            -code: "CA"
          }
          2 => Geocoder\Model\AdminLevel {#921
            -level: 2
            -name: "Los Angeles County"
            -code: "Los Angeles County"
          }
        ]
      }
      -country: Geocoder\Model\Country {#922
        -name: "United States"
        -code: "US"
      }
      -timezone: null
      -providedBy: "google_maps"
    }
  ]
}```
StanBarrows commented 7 years ago

Unfortunately yes. This following comand is the only i get working.

app('geocoder')->geocode('8.8.8.8')->get();

StanBarrows commented 7 years ago

@mikebronner I just saw an closed ticket with someone else having the same problem.

Is there a way I can provide you some log files or access to the server or application? I try to dig into the package a little deeper when i'm at home later to check the package-code by myself as well.

The only thing i'm not getting is why i get an empty collection even if i provide no API_Key. So maybe there is something i'm missing out before its running the actual query. Cheers, Stan

mikebronner commented 7 years ago

Did you remove the alias and provider entries from your config/app.php file? The package is self-registering. Other than that, I have no idea what's going on with your setup. I am unable to reproduce the issue, and suspect that it has something to do with your specific setup.

An empty collection is returned when a result cannot be found, for whatever reason. Please empty your storage/logs/laravel.log file, run the code in Tinkerer, then see if it logged an error. If so, please provide that. If there is no error being logged, I'm afraid it is something with your setup.

Clone the repo to a folder and try running all the unit tests:

  1. git clone git@github.com:geocoder-php/GeocoderLaravel.git
  2. cd GeocoderLaravel
  3. composer update
  4. vendor/bin/phpunit
StanBarrows commented 7 years ago

@mikebronner

Tinker What line of code are you exactly running in Tinker? At the moment i get an 'geocoder' does not exist or an 'not found ine vil()'code Exception.

Unit Tests The UnitTests all passing locally and on the Ubuntu Server as well.

I replaced my API:Key in your Test-Package to make sure the my key is correct. That worked fine, even with an broken key i got the appropriate error response.

Try your TestCode inside my App I was starting running your tests inside my application:

 public function testItResolvesAGivenAddress()
    {

       $results = app('geocoder')
            ->using('chain')
            ->geocode('1600 Pennsylvania Ave., Washington, DC USA')
            ->get();
    }

With the same results: Empty collection.

Cheers, Stan

mikebronner commented 7 years ago

@StanBarrows you didn't answer if you made sure that you weren't manually registering the provider and alias? I can't really help with configuration issues without having a stacktrace or other information.

My recommendation at this point is to read the README in detail and follow it EXACTLY on a new project, and see if it works there. If it does, see what you did differently, or perhaps what might be conflicting with it.

StanBarrows commented 7 years ago

@mikebronner Sorry for that, I re-arranged my comments and forgot to past it back in. Yes, I made sure everything was setup from scratch and the Providers and Facades were removed. At last step i can give it a shot on a completely new project.

Cheers, Stan

StanBarrows commented 7 years ago

@mikebronner

After a restart and clearing ALL possible caches it worked! Thanks for your help and patience. Glad i can user your awesome work now!

I think it's maybe worth to mention somewhere in the documentation again to clear all caches after every possible change on the query.

Cheers Stan

mikebronner commented 7 years ago

Good to hear! Yea, I will update the documentation and also create another issue to look into the caching mechanism to make sure that the cache keys are unique.

StanBarrows commented 7 years ago

Locking back, I'm sure it was a caching problem and I fixed the query maybe after your first post 👍

mikehins commented 6 years ago

Be sure that you use the right type of key

Screenshot from the google api console :

image

mikebronner commented 6 years ago

Thanks for mentioning that @mikehins :)

zhengfen commented 6 years ago

@StanBarrows How to ' clearing ALL possible caches '? I have exactly the same problem, and simply cache:clear doesn't solve the problem. Thank you in advance

zhengfen commented 6 years ago

dd(app('geocoder')->geocode('8.8.8.8')->get()); Illuminate\Support\Collection {#763

items: array:1 [

0 => Geocoder\Model\Address {#765 -coordinates: Geocoder\Model\Coordinates {#783 -latitude: 37.751 -longitude: -97.822 } -bounds: null -streetNumber: null -streetName: null -subLocality: null -locality: null -postalCode: null -adminLevels: Geocoder\Model\AdminLevelCollection {#777 -adminLevels: [] } -country: Geocoder\Model\Country {#784 -name: "United States" -code: "US" } -timezone: null -providedBy: "geo_plugin" } ] }

dd(app('geocoder')->geocode('Los Angeles, CA')->get()); Illuminate\Support\Collection {#763

items: []

}