Skip to content

Receiving an Empty Collection #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
StanBarrows opened this issue Oct 22, 2017 · 24 comments
Closed

Receiving an Empty Collection #104

StanBarrows opened this issue Oct 22, 2017 · 24 comments
Assignees

Comments

@StanBarrows
Copy link

StanBarrows commented Oct 22, 2017

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
Copy link
Member

What version of Mac are you on?

@StanBarrows
Copy link
Author

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
Copy link
Member

mikebronner commented Oct 22, 2017

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
Copy link
Author

StanBarrows commented Oct 22, 2017

@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
Copy link
Member

What is your server OS and version?

@StanBarrows
Copy link
Author

@mikebronner - Its an Ubuntu 16.04.1 LTS

@StanBarrows
Copy link
Author

@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
Copy link
Member

mikebronner commented Oct 22, 2017

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
Copy link
Author

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
Copy link
Author

StanBarrows commented Oct 22, 2017

@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
Copy link
Member

mikebronner commented Oct 22, 2017

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
Copy link
Author

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

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

@StanBarrows
Copy link
Author

@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
Copy link
Member

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
Copy link
Author

StanBarrows commented Oct 22, 2017

@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
Copy link
Member

@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
Copy link
Author

@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
Copy link
Author

StanBarrows commented Oct 22, 2017

@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
Copy link
Member

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
Copy link
Author

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

@mikehins
Copy link

mikehins commented Dec 6, 2017

Be sure that you use the right type of key

Screenshot from the google api console :

image

@mikebronner
Copy link
Member

Thanks for mentioning that @mikehins :)

@zhengfen
Copy link

@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
Copy link

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: []
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants