alexpechkarev / google-maps Goto Github PK
View Code? Open in Web Editor NEWCollection of Google Maps API Web Services for Laravel
Home Page: https://alexpechkarev.github.io/google-maps/
License: MIT License
Collection of Google Maps API Web Services for Laravel
Home Page: https://alexpechkarev.github.io/google-maps/
License: MIT License
Please update README.md file
Change
'providers' => [
...
'GoogleMaps\ServiceProvider\GoogleMapsServiceProvider',
]
'aliases' => [
...
'GoogleMaps' => 'GoogleMaps\Facade\GoogleMapsFacade',
]
To
'providers' => [
...
GoogleMaps\ServiceProvider\GoogleMapsServiceProvider::class,
'aliases' => [
...
GoogleMaps' => GoogleMaps\Facade\GoogleMapsFacade::class,
]
This is very misleading for people who would just copy the code and paste in their file. Awesome project.
local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Can't use function return value in write context' in /var/www/'user'l/httpdocs/laravel/vendor/alexpechkarev/google-maps/src/WebService.php:268
Hi i just started using laravel as framework and am almost done with my project with it. I have a problem with the google-maps. Everytime i try this code
$response = \GoogleMaps::load('geocoding')->setParam (['address' =>'santa cruz'])->get();
I get the error thats written above.
If you can please help me with this issue ill be really grateful.
Good day, so I am working on a project for a real estate agency, and to provide more information for users seeking to find an apartment I would like to add a feature were nearby locations like schools, restaurants, night clubs and so on can be shown and I have been finding it very difficult.
So here's the question, can I load more than one serviceName, and if I can, how do I get responses for each service. See example
$response = \GoogleMaps::load('geocoding', 'nearbysearch', placeadd)
->setParamByKey('address', $property->address)
->setParamByKey('latlng', [how do I reference the lat and lng here])
->setParamByKey('radius', 1500)
->get('results.geometry.location');
Note that the property address comes directly from the database dynamically. I really hope I made sense. I would need help.
Can i use this to add a map to my view which shows a location based on postcode.
If so can you give me an example on how i can do this. (I have the package configured and setup already)
thank you in advance.
Hi Alex,
is it possible to make a signed request to google (directions api) in order to get the duration_in_traffic response? I'm building a dashboard for my family to show how long everybody needs to get to work, school etc.
Best regards,
Rene
Hi, under PHP 7.2 WebService.php line 305 throws an error exception when uses the count() function, and could do with a guard to ensure the config key variable is an instance of countable
How to access the array in ->get('routes');
in Directions API?
The types parameter has been depricated in favor of a single type now is indicated in their documentation:
https://developers.google.com/places/web-service/search
You might want to update your code
in my food delivery system i need to divide city to multiple zone and set price of each zone for delivery system
can I use this package to create polygon and check user location is in any polygons?
Hi Alex.
I try to deploy my laravel project. But I got this error
ErrorException in WebService.php line 372:
curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set
It works perfectly at localhost. If you please help me with this issue I'll be really grateful.. Thanks..
Could you use this to pin multiple locations on a single map for like a overview of locations?
Hi,
Actually, it's not an issue - but this is the only way I can contact you.
Does this package support the following case:
To check if an address falls within another address using Lat/Long and Radius.
Thanks.
How do you use the distancematrix from google?
Dont seem to figure out how to pass the origins and destinations..
Hello,
I experienced this issue running laravel 5.3 project
PHP Fatal error: Class 'GoogleMaps\ServiceProvider\GoogleMapsServiceProvider' not found
I add these lines to config/app.php
--> Providers
GoogleMaps\ServiceProvider\GoogleMapsServiceProvider::class,
--> Alias
'GoogleMaps' => GoogleMaps\Facade\GoogleMapsFacade::class,
Composer update is running fine and install your library with no issue.
I try
composer dump-autoload -o
No luck with this
Have an idea ?
Thanks a lot
I have been trying to do the following
public function index()
{
$d = \GoogleMaps::load('directions')->setEndpoint('json')
->setParamByKey('origin', 'Bengaluru')
->setParamByKey('destination', 'Kolkata')->get();
// echo $d;
$json_a= json_decode($d,true);
echo $json_a->geocoded_waypoints[0]->geocoder_status;
But I am not getting any values .Can anyone please help me out
php artisan vendor:publish --tag=googlemaps --force
does not create any file in config.
Work around: I had to copy it manually
Hello.
Can i use this class Wihout framework Laravel?
Hi,
Is there a way to get user current location?
thanks
I am using framework ThinkPHP 5.1, I wish I can run this package on this farmwork as well..plz
Hello,
I'm trying to do a search with geocoding library for the locality "Póvoa de Santa Iria, Portugal".
What is happening is that params are being encoded 2 times, and because of portuguese characters, url is distorted and no results are found.
Here is the difference:
Url by hand:
https://maps.googleapis.com/maps/api/geocode/json?key=[key]&components=locality:Póvoa de Santa Iria, Portugal
With the package it becomes
https://maps.googleapis.com/maps/api/geocode/json?key=[key]&components=locality%3AP%25C3%25B3voa%2Bde%2BSanta%2BIria,%2BPortugal
Hi.
why can't i insert a string in destinations ($localdest) in this code?
$d = \GoogleMaps::load('distancematrix')
->setParam([
'origins' => [$localorig],
'destinations' => [$localdest],
])
->getResponseByKey('distance');
Anyone can help?
Hi,
if I try:
\GoogleMaps::load('directions') ->setParam([ 'origin' => "Barcelona, ES", 'destination' => "Madrid, ES", ]) ->get();
works properly.
When I try:
\GoogleMaps::load('directions') ->setParam([ 'origin' => ['lat' => 41.3850639, 'lng' => 2.1734035], 'destination' => ['lat' => 40.4167754, 'lng' => -3.7037902], ]) ->get();
the response is:
{"geocoded_waypoints":[{"geocoder_status":"ZERO_RESULTS"},{"geocoder_status":"ZERO_RESULTS"}],"routes":[],"status":"NOT_FOUND"}
Someone has been able to use directions API with lat/lng parameters?
Thanks.
Can i get floor/door(premise) numbers and street numbers with postcode.
Hi, how can return multiples paramters? i need return name, photo, address, etc.
i tried with this
get('response.name.photo')
get('response.['name.,photo']')
but the response is all parameters.
In joinParam method of Parameters.php
return !is_null( $allParam )
? implode($glue, str_replace(['%252C'],[','],$allParam) )
:'';
should be replaced by
return !is_null( $allParam )
? implode($glue, str_replace(['%7C'],['|'],str_replace(['%252C'],[','],$allParam)) )
:'';
in order to managed a list of lat/lon when calling an "elevation" Google service.
This is cause be the encoding replacing "|" by the encoded value (%7C). There might be also a different way to do that.
Have no idea what this is "unserialize(): Error at offset 0 of 40 bytes". What caused the problem of this error?
Hello i would like to get the shortest way from a point A to a point B and not the fastest. So i looked around on the forums and i found alternatives=true param who gives you different alternatives.
How could i check the differents way ? actually i have this in my controller to calculate the distance * 2. I simply whould like to check if there is a shortest way and if it is i get the shortest way. hope you could help me. thanks a lot in advance
`$origin = $licencie->lb_adresse .' '. $licencie->lb_ville_naissance .' '. $licencie->cd_dept_naissance;
$destination = $rencontre->stade->adresse_stade .' '. $rencontre->stade->ville_stade .' '. $rencontre->stade->cd_post_stade;
$response = \GoogleMaps::load('directions')
->setParam([
'origin' => $origin,
'destination' => $destination,
'mode' => 'driving' ,
//'alternatives' => true,
'language' => 'fr',
])->get();
$parsed_json = (json_decode($response));
$result = $parsed_json->{'routes'}[0]->{'legs'}[0]->{'distance'}->{'text'};
$a = $result;
$b = str_replace(" km",'',$a);
$distance = str_replace(",",'.',$b);
//distance * 2
$distance = $distance * 2 ;`
This request works (replace MYKEY with your key) :
https://maps.googleapis.com/maps/api/elevation/json?key=<MYKEY>&locations=45.523720,-73.538790|45.524540,-73.538650|45.525100,-73.538500|45.525840,-73.538200|45.526270,-73.537990|45.526920,-73.537570|45.527280,-73.537310|45.527740,-73.536910|45.528110,-73.536650|45.529090,-73.535880|45.529040,-73.535120|45.528870,-73.532620|45.529050,-73.535320|45.529080,-73.535780|45.527880,-73.536690|45.527810,-73.536730|45.527720,-73.536760|45.527630,-73.536720|45.527310,-73.536590|45.526910,-73.536390|45.526880,-73.536330|45.527060,-73.535700|45.527060,-73.535580|45.526960,-73.534920|45.526930,-73.534840|45.526840,-73.534710|45.526690,-73.534610|45.526620,-73.534470|45.526540,-73.534240|45.526470,-73.534200|45.525940,-73.534040|45.525890,-73.534030|45.525850,-73.533860|45.525800,-73.533690|45.525520,-73.533220|45.525000,-73.532430|45.524840,-73.532130|45.524720,-73.532010|45.524660,-73.531970|45.524540,-73.531930|45.524410,-73.531900|45.524060,-73.531880|45.523010,-73.531880|45.522120,-73.531790|45.521760,-73.531770|45.519710,-73.531480|45.519300,-73.531390|45.519220,-73.531360|45.518860,-73.531150|45.518770,-73.531150|45.518470,-73.531030|45.518210,-73.530900|45.518050,-73.530850|45.517740,-73.530780|45.517070,-73.530650|45.515930,-73.530420|45.515610,-73.530350|45.515340,-73.530260|45.515080,-73.530170|45.514860,-73.530150|45.514530,-73.530170|45.514230,-73.530260|45.514090,-73.530320|45.513680,-73.530570|45.513400,-73.530690|45.512990,-73.530790|45.512960,-73.530800|45.512990,-73.530790|45.512990,-73.530570|45.512970,-73.527880|45.512150,-73.527880|45.511710,-73.527930|45.511320,-73.528020|45.510890,-73.528130|45.510350,-73.528340|45.509720,-73.528620|45.509510,-73.528640|45.509260,-73.528630|45.509010,-73.528570|45.508880,-73.528490|45.508810,-73.528440|45.508790,-73.528420|45.508910,-73.528270|45.509000,-73.528180|45.509230,-73.528060|45.509610,-73.527900|45.510240,-73.527660|45.511060,-73.527430|45.511630,-73.527300|45.512040,-73.527270|45.512300,-73.527270|45.512530,-73.527280|45.512750,-73.527320|45.513640,-73.527570|45.514100,-73.527700|45.514180,-73.527690|45.514240,-73.527640|45.514260,-73.527610|45.514290,-73.527550|45.514300,-73.527480|45.514280,-73.527390|45.514240,-73.527290|45.514120,-73.527220|45.513730,-73.527150|45.513450,-73.527130|45.513320,-73.527100|45.513120,-73.527010|45.512410,-73.526530|45.510260,-73.525350|45.510010,-73.525240|45.507920,-73.524610|45.503920,-73.523440|45.503340,-73.523240|45.503330,-73.523240|45.503170,-73.523240|45.502740,-73.523330|45.502630,-73.523320|45.499710,-73.522440|45.499390,-73.522390|45.499260,-73.522380|45.499110,-73.522390|45.498950,-73.522370|45.497700,-73.521990|45.497480,-73.521950|45.497280,-73.521940|45.497160,-73.522020|45.497070,-73.522170|45.497040,-73.522430|45.497070,-73.522760|45.497150,-73.523200|45.497350,-73.523970|45.497450,-73.524220|45.497670,-73.524640|45.498750,-73.526350|45.499130,-73.526840|45.499480,-73.527220|45.500010,-73.527730|45.500440,-73.528090|45.501280,-73.528710|45.501640,-73.528960|45.502180,-73.529240|45.502720,-73.529470|45.502890,-73.529540|45.503720,-73.529780|45.503940,-73.529820|45.504830,-73.529910|45.505530,-73.529940|45.505790,-73.529920|45.506590,-73.529820|45.507130,-73.529680|45.507790,-73.529440|45.508560,-73.529130|45.508497,-73.528748|45.508151,-73.528748|45.507956,-73.528962|45.508016,-73.529842|45.508250,-73.531550|45.508340,-73.532220|45.508370,-73.532550|45.508390,-73.532680|45.508380,-73.532810|45.508370,-73.532930|45.508300,-73.533130|45.508240,-73.533190|45.507880,-73.534260|45.507500,-73.535290|45.507280,-73.535900|45.504900,-73.542340|45.504900,-73.542490|45.504740,-73.542920|45.504550,-73.543390|45.504390,-73.543660|45.504210,-73.543850|45.504020,-73.543970|45.503890,-73.544020|45.503740,-73.544040|45.503580,-73.544060|45.503510,-73.544060|45.503410,-73.544010|45.502160,-73.544140|45.500040,-73.544380|45.497820,-73.544650
fails.
It looks like Google does not accept more than 2048 characters as parameters.
It would by nice if your library could break the request into many requests and returns the concatenated request so the this limitation would by hidden from the caller.
Or any other way to bybass the limitation properly?
Thanks
Hi there, how r u?
I'm facing a problem, when I make a few requests, for some of them i get no route. when i go to google maps and input same data, i get routes from there. can give any idea what is going on?
thank you
I would like to report an issue that I am facing.
I installed this package with laravel 5.3.
Whenever I am calling placedetails method like below
$location = \GoogleMaps::load('place_details')
->setParam(['placeid' => 'ChIJN1t_tDeuEmsRUsoyG83frY4'])->get();
I am getting following exception.
in WebService.php line 141
at HandleExceptions->handleError('2', 'array_merge(): Argument #1 is not an array', '/Users/avinashmishra/lab/sd/laravel-backend/vendor/alexpechkarev/google-maps/src/WebService.php', '141', array('param' => array('placeid' => 'ChIJN1t_tDeuEmsRUsoyG83frY4'), 'this' => object(GoogleMaps)))
at array_merge(null, array('placeid' => 'ChIJN1t_tDeuEmsRUsoyG83frY4')) in WebService.php line 141
at WebService->setParam(array('placeid' => 'ChIJN1t_tDeuEmsRUsoyG83frY4')) in ApisController.php line 23
at ApisController->location(object(Request))
at call_user_func_array(array(object(ApisController), 'location'), array(object(Request))) in Controller.php line 55
at Controller->callAction('location', array(object(Request))) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(ApisController), 'location') in Route.php line 189
at Route->runController() in Route.php line 144
at Route->run(object(Request)) in Router.php line 642
at Router->Illuminate\Routing{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing{closure}(object(Request)) in ThrottleRequests.php line 49
at ThrottleRequests->handle(object(Request), object(Closure), '60', '1') in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Router.php line 644
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 618
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 268
at Kernel->Illuminate\Foundation\Http{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 150
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
at Kernel->handle(object(Request)) in index.php line 53
Can I pass CURLOPT_REFERER to the request?
Is there any parameter key?
hello,
i want to pass an array of waypoints to the directions service but it is not working.
even converting the array to a string does not work.
when i use: 'waypoints' => [$array]', it is not working, even when array is a string like: 'Vancouver BC', 'Seattle'.
But when i type this, and not use a variable, it does work.
Can you help me?
When request to google maps shows error 404 in google
Hello, do you plan to update the code to work with Laravel 6?
how can I put directions with your package ?
-- 'GoogleMaps' => ' GoogleMaps\Facade\GoogleMapsFacade',
There's an extra space in the value of the facade config. Took me 20 minutes to figure out why it was throwing the error: Class ' GoogleMaps\Facade\GoogleMapsFacade' not found
I test the doc example but it always return false, is there any thing wrong ?
`$response = \GoogleMaps::load('directions')
->setParam([
'origin' => 'place_id:ChIJ685WIFYViEgRHlHvBbiD5nE',
'destination' => 'place_id:ChIJA01I-8YVhkgRGJb0fW4UX7Y',
])
->containsLocation(55.86483,-4.25161);
dd( $response ); // true`
I try my api key with google example here https://developers.google.com/maps/documentation/javascript/examples/poly-containsLocation it work
I am workin on laravel project in which i have to integrate google maps. I am using this package https://github.com/alexpechkarev/google-maps for google maps . I install this package and get api key from https://console.developers.google.com/apis/credentials . then I just follow the usage of this package for example i write the code in my controller
$response = \GoogleMaps::load('geocoding')
->setParam (['address' =>'santa cruz'])
->get();
It giving me data in json encode formate but i dont know what i do next . How can i display maps in view blade.php . can someone please give me proper example of this package via code i will be thankfull for that thanks in advanced
Hi, I'm working on an app that should filter the nearby items within a radius of 20km. I have stored in db lat and lng, how could I implement it in your plugin? I searched but I do not understand and I need your help.
Thank you for your awesome contributions!
Hello,
I need to obtain the API key dynamically from a database, depending on the application instance.
It cannot be obtained statically from the config file.
Are there any way to set it per API call, or dynamically set it on the config options? Thanks.
$response->setEndpoint('json')->get();
return json with html header
and I have to use :
return response($response)->header('Content-Type', 'application/json');
to set header
Can you please update the package.json to add laravel 5.5 compatibility?
Hi
I just installed your library and it looks pretty cool. Just wondering if there is any method to decode the polyline point returned in Directions response. Here is Directions API response:
{
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJlfTBINcEGTkR_Wu1RAUpDYI",
"types" : [ "street_address" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJlfTBINcEGTkR_Wu1RAUpDYI",
"types" : [ "street_address" ]
}
],
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 31.5562273,
"lng" : 74.3571711
},
"southwest" : {
"lat" : 31.55462439999999,
"lng" : 74.3546016
}
},
"copyrights" : "Map data ©2015 Google",
"legs" : [
{
"distance" : {
"text" : "0.3 km",
"value" : 302
},
"duration" : {
"text" : "1 min",
"value" : 45
},
"end_address" : "132 Allama Iqbal Road, Lahore, Pakistan",
"end_location" : {
"lat" : 31.5562273,
"lng" : 74.3546016
},
"start_address" : "132 Allama Iqbal Road, Lahore, Pakistan",
"start_location" : {
"lat" : 31.55462439999999,
"lng" : 74.3571711
},
"steps" : [
{
"distance" : {
"text" : "0.3 km",
"value" : 302
},
"duration" : {
"text" : "1 min",
"value" : 45
},
"end_location" : {
"lat" : 31.5562273,
"lng" : 74.3546016
},
"html_instructions" : "Head \u003cb\u003enorthwest\u003c/b\u003e on \u003cb\u003eAllama Iqbal Rd\u003c/b\u003e",
"polyline" : {
"points" : "k_r_Ei{ydM[r@e@bAOZWh@Ub@]p@c@`AU^e@p@cAxA"
},
"start_location" : {
"lat" : 31.55462439999999,
"lng" : 74.3571711
},
"travel_mode" : "DRIVING"
}
],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "k_r_Ei{ydMiB|Ds@tAy@`BiBjC" // this is the encoded polyline point to decode
},
"summary" : "Allama Iqbal Rd",
"warnings" : [],
"waypoint_order" : []
}
],
"status" : "OK"
}
I already decoded the point in JS, I need your help to do same using this library.
Thanks
Hi,
I'm currently working on a project that involves google maps turn by turn directions.
I encounter this error, what could be the cause of this?
Call to undefined method Illuminate\Support\Facades\GoogleMapsFacade::load()
I placed the GoogleMapsFacade.php to Illuminate\Support\Facades\ directory.
Thanks in advance.
I'm trying to display google map on the view. But I can't displaying it as a map.
I think I am missing something but couldn't sure what.
here it is a example of my controller and view.
public function map()
{
$response = \GoogleMaps::load('geocoding')
->setParam(['address' => 'tokyo'])
->get();
return view('welcome', compact('response'));
}
<div style="width: 500px; height: 500px;">
{{ $response }}
</div>
what i am missing here: it returns on page like this.
{ "results" : [ { "address_components" : [ { "long_name" : "Tokyo", "short_name" : "Tokyo", "types" : [ "administrative_area_level_1", "locality", "political" ] }, { "long_name" : "Japan", "short_name" : "JP", "types" : [ "country", "political" ] } ], "formatted_address" : "Tokyo, Japan", "geometry" : { "bounds" : { "northeast" : { "lat" : 35.8986468, "lng" : 153.9876115 }, "southwest" : { "lat" : 24.2242626, "lng" : 138.942758 } }, "location" : { "lat" : 35.6894875, "lng" : 139.6917064 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 35.817813, "lng" : 139.910202 }, "southwest" : { "lat" : 35.528873, "lng" : 139.510574 } } }, "place_id" : "ChIJ51cu8IcbXWARiRtXIothAS4", "types" : [ "administrative_area_level_1", "locality", "political" ] } ], "status" : "OK" }
Have this exception running php 7.2 laravel 5.5
ErrorException count(): Parameter must be an array or an object that implements Countable
/vendor/alexpechkarev/google-maps/src/WebService.php:305
// Validate Endpoint
if(!array_key_exists('endpoint', config('googlemaps') )
|| !count(config('googlemaps.endpoint') < 1)){
throw new \ErrorException('End point must not be empty.');
}
Thanks for this great package to manage google APIs, I am wondering if it works with Lumen?
Setting the parameter optimizeWaypoints to true doesn't change the response.
In the example from maps api documentation destinations are set this way:
(...)waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA
The curl request in this library adds the optimizeWaypoints=true to the end of the URL which doesn't return the array optimized_waypoints order correctly.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.