Closed Norgul closed 6 years ago
Hi @Norgul, For Laravel 5.5 it is important NOT to register the provider manually. That might be causing the issue. Please remove the provider from config/app.php
and try again and let me know how that goes.
Also, try using the default config first, before publishing the config. Go ahead and delete the published config file and try again.
Let me know how those go, and we'll go from there.
I thought only alias was automatically registered. Anyway, I removed the provider and ran composer dump-autoload
. Also deleted the config file. Same thing happens
OK, lets try running the unit tests next. SSH into Laravel Homestead, and go to your project folder. Then type the following:
cd vendor/toin0u/geocoder-laravel
composer install
vendor/bin/phpunit
Please run the tests a few times if you get errors, as some of the services block access temporarily from local dev environments. If you get consistent errors, please paste them here.
Please update to the latest version of the package. You should be running 4.0.3. Also, please make sure to clear you cache and try again.
php artisan cache:clear
I think that Mockery failed composer installation for some reason, and when I repeat the process it says there is nothing to install or update.
When I ran the tests, every test failed, but I don't see how it should pass if Mockery isn't installed.
The "readable" errors I could see were something like:
vendor/toin0u/geocoder-laravel/tests/Laravel5_5/Providers/GeocoderServiceTest.php:26
Caused by
PDOException: could not find driver
vendor/toin0u/geocoder-laravel/tests/Laravel5_5/Providers/GeocoderServiceTest.php:26
Caused by
Doctrine\DBAL\Driver\PDOException: could not find driver
9) Geocoder\Laravel\Tests\Laravel5_5\Providers\GeocoderServiceTest::testConfig
Illuminate\Database\QueryException: could not find driver (SQL: select * from sqlite_master where type = 'table' and name = migrations)
I tried deleting the vendor file and doing composer install
again after clearing composer cache, and now even more failed packages
It looks like you might have some internet connectivity issues, or perhaps ISP issues, which might be causing your lookups to fail. At this point I don't see anything that points to the package causing the problem.
Oh, actually now I see that below that it says Downloading 100%...so it is downloading it after all.
I ran the tests again, this is the first one on the list
EEEEEEEEEEEEEEEEEEEEEEEEEE 26 / 26 (100%)
Time: 2.6 seconds, Memory: 22.00MB
There were 26 errors:
1) Geocoder\Laravel\Tests\Laravel5_5\Providers\GeocoderServiceTest::testItReverseGeocodesCoordinates
Illuminate\Database\QueryException: could not find driver (SQL: select * from sqlite_master where type = 'table' and name = migrations)
Also if I try to do this:
return \Geocoder::geocode('Los Angeles, CA')->all();
I get the error response that class Geocoder is not found? How is that possible if it registers it automatically?
I also tried diving into the code and dumping $this->aggregator->getProviders()
and I am only getting back
{
"chain": {}
}
Is that the problem? Why isn't GoogleMaps registered?
Is Google maps API key mandatory? I suppose it is, I tried with JS API key, and embed API key, and with no key at all. Same result
On the sidenote, I am running my environment inside a Vagrant box
Sorry @Norgul at this point it looks more like something with your project, implementation, configuration, or development environment. :( Please try an a fresh Laravel project and make sure GeocoderLaravel is up-to-date.
I tried the fresh installation also, and I get the same result.
Could you confirm two things:
I tried using Google Geocoding API key instead of Google Maps one (since that says under original repository, tests section) but still nothing.
Installing fresh Laravel app even on another machine (Win 10), even with new homestead, returns empty set. Clearing all cache didn't help either. Running Chrome in incognito didn't help.
One thing I noticed in the documentation was saying to set HTTPS to true, but I didn't see that option anywhere?
I honestly have no idea what might not be right at this time in your project. Is it in a public repo so that I can look at it?
Nope, it's a business private app, but I can put the test repo up...even though I'm not sure what may be the issue or what may be different as I am doing things this way:
OK, post up a test project repo, and I will try to replicate the problem. If it works on my end, it is an environmental issue in your dev environment. If its a code issue I should be able to see it.
What does the Google maps API return on the URL this package tries to address? Had the same issue what you describe and came to the conclusion that Google Maps refused to send me the results.
You mean this?
const GEOCODE_ENDPOINT_URL_SSL = 'https://maps.googleapis.com/maps/api/geocode/json?address=%s';
When I replace the address and paste this to browser I get the results back.
I think you should change the documentation, and on top of that maybe even the code as it is somewhat unclear now.
First, Google API key is not mandatory.
After I did dd(app('geocoder')->geocode('5.43.168.58')->get())
I am infact getting the results back. But saying that it is working as a Laravel collection is I think not true as once again, if I don't die and dump, I see nothing.
Where I'd expect to do app('geocoder')->geocode('5.43.168.58')->get()->country
to fetch country from geocoded result, I actually need to do this:
app('geocoder')->geocode('5.43.168.58')->get()->first()->getCountry()->getName();
This by itself looks in my opinion a bit too complex, but even with that in mind, I'd get to it somehow if I got the dump back on my screen with the simple get()
You can consider this issue closed. Thank you for the time
@Norgul the result you get is a true Laravel Collection consisting of results. You need to operate on each individually as you would otherwise if it weren't a laravel collection. But because it is a laravel collection, you can manipulate it with all the accustomed Collection methods.
Glad to see you have it working.
I'm just referring to what the package had for Laravel 4.2 version. It was like this
Geocoder::geocode('0.0.0.0')->getCity()
Seems like a much cleaner solution in my opinion
It has since been completely overhauled. If you want a more bare-bones implementation, you might consider just pulling in the parent package instead of this one.
I won't get in the reasons of overhaul nor how you meant the package the function. I would just for the sake of users like myself recommend for a bit more details in the documentation about how to actually get the data :)
Sure, I agree :). Please feel free to submit a PR with your suggestions.
Same problem here, but with reverse():
But if I do this with geocode(), It works:
Sorry, I got problems with my API Key. But, I suggest you show or throw an error instead of empty results.
I'm having the same problem with reverse()
returning empty.
How did you solve this issue regarding API key?
Hi, @brentscholl !
I think I did: dd(app('geocoder')->reverse('10.5', '-75.2'));
, then I search for the URL and I click on it. I could see the error in the browser. I had to create a new API Project in Google.
Thanks for the response!
Hmm. Ok the big difference is dd(app('geocoder')->reverse('10.5', '-75.2'))
returns a result. I found the URL. When I click on it, it returns the JSON results.
But dd(app('geocoder')->reverse('10.5', '-75.2')->get()->first())
returns null
I'm having an issue where I can not use getStreetName()
or getCountry()
etc.
dd(app('geocoder')->reverse('10.5', '-75.2')->get()->first()->getCountry());
returns Call to a member function getCountry() on null
Am I doing something wrong?
app('geocoder')->reverse('10.5', '-75.2')->get();
should return a Collection. If it doesn't, it's not working.
This worked for me:
Can you show us your JSON result? It has to look like this:
When I visit the URL https://maps.googleapis.com/maps/api/geocode/json?latlng=52.773613,-108.297923®ion=en-US&key=[MY API KEY HERE]
I get this:
dd(app('geocoder')->reverse('52.7737667', '-108.2977717'));
Gives me an empty collection
dd(app('geocoder')->reverse('52.7737667', '-108.2977717')->get()->first());
is just null
Could you try with use Geocoder\Laravel\Facades\Geocoder;
instead of app('geocoder')
.
Do you see something strange when you do: dd(Geocoder::reverse($this->latitude, $this->longitude))
?
This is what I get:
Geocoder\Laravel\ProviderAndDumperAggregator {#1250
#aggregator: Geocoder\ProviderAggregator {#1234
-providers: array:1 [
"chain" => Geocoder\Provider\Chain\Chain {#1226
-providers: array:2 [
"Geocoder\Provider\GoogleMaps\GoogleMaps" => Geocoder\Provider\GoogleMaps\GoogleMaps {#1251
-region: "es"
-apiKey: "[API_KEY]"
-clientId: null
-privateKey: null
-channel: null
-client: Http\Client\Curl\Client {#1230
-options: []
-messageFactory: Http\Message\MessageFactory\GuzzleMessageFactory {#1233}
-streamFactory: Http\Message\StreamFactory\GuzzleStreamFactory {#1229}
-handle: curl resource {@566
url: "https://maps.googleapis.com/maps/api/geocode/json?latlng=10.568303,-75.338295®ion=es&key=[API_KEY]"
content_type: "application/json; charset=UTF-8"
http_code: 200
header_size: 428
request_size: 161
filetime: -1
ssl_verify_result: 0
redirect_count: 0
total_time: 0.536174
namelookup_time: 0.029547
connect_time: 0.072192
pretransfer_time: 0.256232
size_upload: 0.0
size_download: 9384.0
speed_download: 17501.0
speed_upload: 0.0
download_content_length: -1.0
upload_content_length: -1.0
starttransfer_time: 0.530471
redirect_time: 0.0
redirect_url: ""
primary_ip: "172.217.28.106"
certinfo: []
primary_port: 443
local_ip: "192.168.1.66"
local_port: 33486
}
-multiRunner: null
}
-messageFactory: Http\Message\MessageFactory\GuzzleMessageFactory {#1252}
}
"Geocoder\Provider\GeoPlugin\GeoPlugin" => Geocoder\Provider\GeoPlugin\GeoPlugin {#1257
-client: Http\Client\Curl\Client {#1231
-options: []
-messageFactory: Http\Message\MessageFactory\GuzzleMessageFactory {#1255}
-streamFactory: Http\Message\StreamFactory\GuzzleStreamFactory {#1259}
-handle: null
-multiRunner: null
}
-messageFactory: Http\Message\MessageFactory\GuzzleMessageFactory {#1260}
}
]
#logger: null
}
]
-provider: null
-limit: 5
-decider: "Geocoder\ProviderAggregator::getProvider"
}
#limit: null
#results: Illuminate\Support\Collection {#1228
#items: array:5 [
0 => Geocoder\Provider\GoogleMaps\Model\GoogleAddress {#1344
-id: "ChIJp9WxVooV9o4RwkX_Nm6YOgs"
-locationType: "GEOMETRIC_CENTER"
-resultType: array:1 [
0 => "route"
]
-formattedAddress: "Sta Catalina-Bayunca, Clemencia, Bolívar, Colombia"
-streetAddress: null
-intersection: null
-political: "Colombia"
-colloquialArea: null
-ward: null
-neighborhood: null
-premise: null
-subpremise: null
-naturalFeature: null
-airport: null
-park: null
-pointOfInterest: null
-establishment: null
-subLocalityLevels: Geocoder\Model\AdminLevelCollection {#1347
-adminLevels: []
}
-coordinates: Geocoder\Model\Coordinates {#1339
-latitude: 10.5687494
-longitude: -75.3387248
}
-bounds: Geocoder\Model\Bounds {#1340
-south: 10.5681745
-west: -75.339734
-north: 10.5693243
-east: -75.3377155
}
-streetNumber: null
-streetName: "Santa Catalina-Bayunca"
-subLocality: null
-locality: null
-postalCode: "130517"
-adminLevels: Geocoder\Model\AdminLevelCollection {#1345
-adminLevels: array:2 [
1 => Geocoder\Model\AdminLevel {#1342
-level: 1
-name: "Bolívar"
-code: "Bolívar"
}
2 => Geocoder\Model\AdminLevel {#1341
-level: 2
-name: "Clemencia"
-code: "Clemencia"
}
]
}
-country: Geocoder\Model\Country {#1343
-name: "Colombia"
-code: "CO"
}
-timezone: null
-providedBy: "google_maps"
}
1 => Geocoder\Provider\GoogleMaps\Model\GoogleAddress {#1352
-id: "ChIJRXVAr4sV9o4Rxkxkp8VTPJo"
-locationType: "APPROXIMATE"
-resultType: array:2 [
0 => "locality"
1 => "political"
]
-formattedAddress: "El Socorro, Clemencia, Bolívar, Colombia"
-streetAddress: null
-intersection: null
-political: "Colombia"
-colloquialArea: null
-ward: null
-neighborhood: null
-premise: null
-subpremise: null
-naturalFeature: null
-airport: null
-park: null
-pointOfInterest: null
-establishment: null
-subLocalityLevels: Geocoder\Model\AdminLevelCollection {#1355
-adminLevels: []
}
-coordinates: Geocoder\Model\Coordinates {#1338
-latitude: 10.569009
-longitude: -75.337419
}
-bounds: Geocoder\Model\Bounds {#1348
-south: 10.5676769
-west: -75.339072
-north: 10.5703411
-east: -75.335765
}
-streetNumber: null
-streetName: null
-subLocality: null
-locality: "El Socorro"
-postalCode: null
-adminLevels: Geocoder\Model\AdminLevelCollection {#1353
-adminLevels: array:2 [
1 => Geocoder\Model\AdminLevel {#1350
-level: 1
-name: "Bolívar"
-code: "Bolívar"
}
2 => Geocoder\Model\AdminLevel {#1349
-level: 2
-name: "Clemencia"
-code: "Clemencia"
}
]
}
-country: Geocoder\Model\Country {#1351
-name: "Colombia"
-code: "CO"
}
-timezone: null
-providedBy: "google_maps"
}
2 => Geocoder\Provider\GoogleMaps\Model\GoogleAddress {#1360
-id: "ChIJmw9Oio8V9o4ROYQf5Us6wKE"
-locationType: "APPROXIMATE"
-resultType: array:2 [
0 => "administrative_area_level_2"
1 => "political"
]
-formattedAddress: "Clemencia, Bolívar, Colombia"
-streetAddress: null
-intersection: null
-political: "Colombia"
-colloquialArea: null
-ward: null
-neighborhood: null
-premise: null
-subpremise: null
-naturalFeature: null
-airport: null
-park: null
-pointOfInterest: null
-establishment: null
-subLocalityLevels: Geocoder\Model\AdminLevelCollection {#1363
-adminLevels: []
}
-coordinates: Geocoder\Model\Coordinates {#1346
-latitude: 10.568962
-longitude: -75.3257409
}
-bounds: Geocoder\Model\Bounds {#1356
-south: 10.5046889
-west: -75.3887419
-north: 10.6183249
-east: -75.23376
}
-streetNumber: null
-streetName: null
-subLocality: null
-locality: null
-postalCode: null
-adminLevels: Geocoder\Model\AdminLevelCollection {#1361
-adminLevels: array:2 [
1 => Geocoder\Model\AdminLevel {#1358
-level: 1
-name: "Bolívar"
-code: "Bolívar"
}
2 => Geocoder\Model\AdminLevel {#1357
-level: 2
-name: "Clemencia"
-code: "Clemencia"
}
]
}
-country: Geocoder\Model\Country {#1359
-name: "Colombia"
-code: "CO"
}
-timezone: null
-providedBy: "google_maps"
}
3 => Geocoder\Provider\GoogleMaps\Model\GoogleAddress {#1368
-id: "ChIJXyrP2cYV9o4Ry0zVG1UHAaM"
-locationType: "APPROXIMATE"
-resultType: array:1 [
0 => "postal_code"
]
-formattedAddress: "Clemencia, Bolívar, Colombia"
-streetAddress: null
-intersection: null
-political: "Colombia"
-colloquialArea: null
-ward: null
-neighborhood: null
-premise: null
-subpremise: null
-naturalFeature: null
-airport: null
-park: null
-pointOfInterest: null
-establishment: null
-subLocalityLevels: Geocoder\Model\AdminLevelCollection {#1371
-adminLevels: []
}
-coordinates: Geocoder\Model\Coordinates {#1354
-latitude: 10.5554093
-longitude: -75.3528779
}
-bounds: Geocoder\Model\Bounds {#1364
-south: 10.50464
-west: -75.3887581
-north: 10.6182761
-east: -75.2337771
}
-streetNumber: null
-streetName: null
-subLocality: null
-locality: null
-postalCode: "130517"
-adminLevels: Geocoder\Model\AdminLevelCollection {#1369
-adminLevels: array:2 [
1 => Geocoder\Model\AdminLevel {#1366
-level: 1
-name: "Bolívar"
-code: "Bolívar"
}
2 => Geocoder\Model\AdminLevel {#1365
-level: 2
-name: "Clemencia"
-code: "Clemencia"
}
]
}
-country: Geocoder\Model\Country {#1367
-name: "Colombia"
-code: "CO"
}
-timezone: null
-providedBy: "google_maps"
}
4 => Geocoder\Provider\GoogleMaps\Model\GoogleAddress {#1375
-id: "ChIJhWiv4EXQWI4RFZYP9gSTAaY"
-locationType: "APPROXIMATE"
-resultType: array:2 [
0 => "administrative_area_level_1"
1 => "political"
]
-formattedAddress: "Bolivar, Colombia"
-streetAddress: null
-intersection: null
-political: "Colombia"
-colloquialArea: null
-ward: null
-neighborhood: null
-premise: null
-subpremise: null
-naturalFeature: null
-airport: null
-park: null
-pointOfInterest: null
-establishment: null
-subLocalityLevels: Geocoder\Model\AdminLevelCollection {#1378
-adminLevels: []
}
-coordinates: Geocoder\Model\Coordinates {#1362
-latitude: 8.6704382
-longitude: -74.0300122
}
-bounds: Geocoder\Model\Bounds {#1372
-south: 6.999522
-west: -75.7991099
-north: 10.803259
-east: -73.7470541
}
-streetNumber: null
-streetName: null
-subLocality: null
-locality: null
-postalCode: null
-adminLevels: Geocoder\Model\AdminLevelCollection {#1376
-adminLevels: array:1 [
1 => Geocoder\Model\AdminLevel {#1373
-level: 1
-name: "Bolivar"
-code: "Bolivar"
}
]
}
-country: Geocoder\Model\Country {#1374
-name: "Colombia"
-code: "CO"
}
-timezone: null
-providedBy: "google_maps"
}
]
}
}
I tried what you suggest. Just the same result.
ProviderAndDumperAggregator {#954 ▼
#aggregator: ProviderAggregator {#955 ▼
-providers: array:1 [▼
"chain" => Chain {#982 ▼
-providers: array:2 [▼
"Geocoder\Provider\GoogleMaps\GoogleMaps" => GoogleMaps {#969 ▼
-region: "es"
-apiKey: "[MY API KEY]"
-clientId: null
-privateKey: null
-channel: null
-client: Client {#963 ▼
-options: []
-messageFactory: GuzzleMessageFactory {#965}
-streamFactory: GuzzleStreamFactory {#967}
-handle: curl resource @437 ▼
url: "https://maps.googleapis.com/maps/api/geocode/json?latlng=52.773613,-108.297923®ion=es&key={MY API KEY]"
content_type: null
http_code: 0
header_size: 0
request_size: 0
filetime: -1
ssl_verify_result: 20
redirect_count: 0
total_time: 0.297
namelookup_time: 1.0E-6
connect_time: 0.125
pretransfer_time: 0.0
size_upload: 0.0
size_download: 0.0
speed_download: 0.0
speed_upload: 0.0
download_content_length: -1.0
upload_content_length: -1.0
starttransfer_time: 0.0
redirect_time: 0.0
redirect_url: ""
primary_ip: "172.217.2.170"
certinfo: []
primary_port: 443
local_ip: "192.168.0.101"
local_port: 60896
}
-multiRunner: null
}
-messageFactory: GuzzleMessageFactory {#970}
}
"Geocoder\Provider\GeoPlugin\GeoPlugin" => GeoPlugin {#977 ▶}
]
#logger: null
}
]
-provider: null
-limit: 5
-decider: "Geocoder\ProviderAggregator::getProvider"
}
#limit: null
#results: Collection {#1025 ▼
#items: []
}
}
config/geocoder.php:
<?php
use Geocoder\Provider\Chain\Chain;
use Geocoder\Provider\GeoPlugin\GeoPlugin;
use Geocoder\Provider\GoogleMaps\GoogleMaps;
use Http\Client\Curl\Client;
return [
'cache' => [
/*
|-----------------------------------------------------------------------
| Cache Store
|-----------------------------------------------------------------------
|
| Specify the cache store to use for caching. The value "null" will use
| the default cache store specified in /config/cache.php file.
|
| Default: null
|
*/
'store' => null,
/*
|-----------------------------------------------------------------------
| Cache Duration
|-----------------------------------------------------------------------
|
| Specify the cache duration in minutes. The default approximates a
| "forever" cache, but there are certain issues with Laravel's forever
| caching methods that prevent us from using them in this project.
|
| Default: 9999999 (integer)
|
*/
'duration' => 9999999,
],
/*
|---------------------------------------------------------------------------
| Providers
|---------------------------------------------------------------------------
|
| Here you may specify any number of providers that should be used to
| perform geocaching operations. The `chain` provider is special,
| in that it can contain multiple providers that will be run in
| the sequence listed, should the previous provider fail. By
| default the first provider listed will be used, but you
| can explicitly call subsequently listed providers by
| alias: `app('geocoder')->using('google_maps')`.
|
| Please consult the official Geocoder documentation for more info.
| https://github.com/geocoder-php/Geocoder#providers
|
*/
'providers' => [
Chain::class => [
GoogleMaps::class => [
env('GOOGLE_MAPS_LOCALE', 'en-US'),
env('GOOGLE_MAPS_API_KEY'),
],
GeoPlugin::class => [],
],
],
/*
|---------------------------------------------------------------------------
| Adapter
|---------------------------------------------------------------------------
|
| You can specify which PSR-7-compliant HTTP adapter you would like to use.
| There are multiple options at your disposal: CURL, Guzzle, and others.
|
| Please consult the official Geocoder documentation for more info.
| https://github.com/geocoder-php/Geocoder#usage
|
| Default: Client::class (FQCN for CURL adapter)
|
*/
'adapter' => Client::class,
/*
|---------------------------------------------------------------------------
| Reader
|---------------------------------------------------------------------------
|
| You can specify a reader for specific providers, like GeoIp2, which
| connect to a local file-database. The reader should be set to an
| instance of the required reader class.
|
| Please consult the official Geocoder documentation for more info.
| https://github.com/geocoder-php/geoip2-provider
|
| Default: null
|
*/
'reader' => null,
];
.env:
GOOGLE_MAPS_LOCALE=es
GOOGLE_MAPS_API_KEY=xxx
Have you tried php artisan cache:clear
?
My config/geocoder.php
is same as yours. and yes tried php artisan cache:clear
same result. I have also done everything Norgul has done.
(also, see my edit answer above for JSON)
dd(app('geocoder')->geocode('5.43.168.58')->get()->first()->getCountry()->getName());
works fine. It is only a problem when I use reverse()
so I feel like my config is all fine? I'm not sure what I'm missing. I'm not using a virtual box, my project is local using php artisan serve
geocode()
almost always works because It doesn't use google maps or any API key. I use Lampp (Xampp). Have you tried stopping your firewall for a moment?
And I'm using this version: "toin0u/geocoder-laravel": "^4.0"
Just tried. Getting same results. Empty Collection
in the Docs it says
you must also use set HTTPS to true
Where is this?
General Information
GeocoderLaravel Version: 4.0 Laravel Version: 5.5 PHP Version: 7.0.0. Operating System and Version: MacOS High Sierra
Issue Description
I am getting an empty array no matter what I do with the package. I have installed it through Composer and added to
app.php
Published the config, which is located in
geocoder.php
And added Google API key to my
.env
file underGOOGLE_MAPS_API_KEY
name.First I tried with
return Geocoder::geocode(request()->ip())->get();
But that returned
[]
. After that I went to check the documentation again and used the example from there:return app('geocoder')->geocode('Los Angeles, CA')->get();
I also tried:
return app('geocoder')->geocode('Los Angeles, CA')->get(1);
return app('geocoder')->geocode('Los Angeles, CA')->all();
But again nothing. What may be the issue?
I cleared the composer and artisan cache, and ran
composer dump-autoload
also. Same issue