-
Notifications
You must be signed in to change notification settings - Fork 102
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
Result always return empty object #101
Comments
Can you paste the method where you are returning the geo coded results? I wonder if the return type is force-typecasting the results? Are you using a return type there? |
@mikebronner no. my code only I've tried changed the |
Please paste the entire method you have your code in. There is no |
@mikebronner only this method i have for if I dd(app('geocoder')->geocode('Los Angeles, CA')->get()) this is the result:
I can't get the value inside |
I am unable to replicate the issue. Unit you can provide me your entire code block, there is not much I can do to help. As previously requested, please provide the entire method that contains your code To inspect your results, you can also do this: |
@mikebronner what code block do you need? Like I said before, I just tried this package to see if its working or not. and my code only this:
the return result is:
I've tried to put |
A route returns a view or html. It will not render objects. Using |
@mikebronner but if you the return statement like what I did, it suppose to return an json object (that's why I cant receive I've done this so many times when trying an query or something else to see if its working or not. And fyi I've tried to call it via controller with same exact code still return same object. |
The objects in the collection aren't Laravel models and won't automatically render to JSON. they are normal PHP objects wrapped in a collection. |
So, is there no way to convert an individual |
@humblecoder You could always do something like this: $json = $geocoderResultCollection
->map(function ($result) {
return json_encode($result);
})
->toJson(); Let me know how that works. |
@mikebronner Hrm, your method returns an empty set. I ended up manually building a hash with each function individually (e.g. |
@humblecoder would you mind sharing your solution? perhaps it will help with #132 |
Basically I did the following (assumes you're inside a Laravel controller): Step 1) Calculate address.
Step 2) Acquire relevant collection value. In my case it's the index of the 'ROOFTOP' object.
Step 2) Call built-in methods on that particular collection value.
|
@humblecoder Thanks for sharing. This will hopefully help others in the meantime. The reason for this limitation is that the underlying Geocoder library does not support automatic conversion to json, like eloquent collections with models do. This package is just a nice wrapper to give standard collections around the objects returned by the Geocoder library. |
@humblecoder @stefensuhat I don't know why I didn't bring this up earlier. You can get the JSON representation via app('geocoder')
->geocode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')
->toJson(); Unfortunately the classes in the collection do not have a |
I have same issue as this on Laravel 6.x and PHP 7.3. Please help.
and the result is:
|
@dungnh try this: It works as a workaround from what @mikebronner mentioned. |
I am getting the same answer, please reopen this error
|
@omarmfs98 Please provide the code you are using to get the output. |
General Information
GeocoderLaravel Version: ^4.0
Laravel Version: 5.5.11
PHP Version: 7.2
Operating System and Version: Windows 10
Description
I have this simple code to try out this package:
return app('geocoder')->geocode('Los Angeles, CA')->get();
But everytime it always return me
this is my geocoder.php:
All GOOGLE_MAPS_API_KEY already setup. If I run
dd(app('geocoder')->geocode('Los Angeles, CA')->get())
I can see the results. Only when I put return it return me empty.The text was updated successfully, but these errors were encountered: