Closed SereiaMaster closed 7 years ago
Did you setup your google api key? https://github.com/2amigos/yii2-google-maps-library/blob/master/ClientAbstract.php#L58
Just realized that the __construct()
should fire the init()
. My bad. nevertheless, try with:
geocliente = new GeocodingClient();
$teste = $geocliente->lookup(
[
'address' => 'Stationsplein, 1012 AB Amsterdam',
'region' => 'Netherlands'
]
);
$geocliente->init();
Should fire the error without API key
Nothing change... not working... Not fire error...
All is null.
you didn't include the API key and nothing changed? Did you tried by adding the API key?
I searched the code ClientAbstract () and realized that Init () looked for the key in the $ App parameters ... I put the parameter there, put a Dump_Var ($geocliente) and look at the code that showed
object(dosamigos\google\maps\services\GeocodingClient)#79 (3) { ["format"]=> string(4) "json" ["params"]=> array(7) { ["address"]=> string(32) "Stationsplein, 1012 AB Amsterdam" ["components"]=> NULL ["bounds"]=> NULL ["location"]=> NULL ["region"]=> string(11) "Netherlands" ["language"]=> NULL ["key"]=> string(39) "AIzaSyCT4r6gm0Cqy4s1ccr0vYk7wuVQhqi558M" } ["_guzzle":"dosamigos\google\maps\ClientAbstract":private]=> object(GuzzleHttp\Client)#80 (1) { ["config":"GuzzleHttp\Client":private]=> array(7) { ["handler"]=> object(GuzzleHttp\HandlerStack)#81 (3) { ["handler":"GuzzleHttp\HandlerStack":private]=> object(Closure)#88 (2) { ["static"]=> array(2) { ["default"]=> object(Closure)#86 (2) { ["static"]=> array(2) { ["default"]=> object(GuzzleHttp\Handler\CurlMultiHandler)#82 (5) { ["factory":"GuzzleHttp\Handler\CurlMultiHandler":private]=> object(GuzzleHttp\Handler\CurlFactory)#83 (2) { ["handles":"GuzzleHttp\Handler\CurlFactory":private]=> array(0) { } ["maxHandles":"GuzzleHttp\Handler\CurlFactory":private]=> int(50) } ["selectTimeout":"GuzzleHttp\Handler\CurlMultiHandler":private]=> int(1) ["active":"GuzzleHttp\Handler\CurlMultiHandler":private]=> NULL ["handles":"GuzzleHttp\Handler\CurlMultiHandler":private]=> array(0) { } ["delays":"GuzzleHttp\Handler\CurlMultiHandler":private]=> array(0) { } } ["sync"]=> object(GuzzleHttp\Handler\CurlHandler)#84 (1) { ["factory":"GuzzleHttp\Handler\CurlHandler":private]=> object(GuzzleHttp\Handler\CurlFactory)#85 (2) { ["handles":"GuzzleHttp\Handler\CurlFactory":private]=> array(1) { [0]=> resource(129) of type (curl) } ["maxHandles":"GuzzleHttp\Handler\CurlFactory":private]=> int(3) } } } ["parameter"]=> array(2) { ["$request"]=> string(10) "" ["$options"]=> string(10) "" } } ["streaming"]=> object(GuzzleHttp\Handler\StreamHandler)#87 (1) { ["lastHeaders":"GuzzleHttp\Handler\StreamHandler":private]=> array(0) { } } } ["parameter"]=> array(2) { ["$request"]=> string(10) "" ["$options"]=> string(10) "" } } ["stack":"GuzzleHttp\HandlerStack":private]=> array(4) { [0]=> array(2) { [0]=> object(Closure)#89 (1) { ["parameter"]=> array(1) { ["$handler"]=> string(10) "" } } [1]=> string(11) "http_errors" } [1]=> array(2) { [0]=> object(Closure)#90 (1) { ["parameter"]=> array(1) { ["$handler"]=> string(10) "" } } [1]=> string(15) "allow_redirects" } [2]=> array(2) { [0]=> object(Closure)#91 (1) { ["parameter"]=> array(1) { ["$handler"]=> string(10) "" } } [1]=> string(7) "cookies" } [3]=> array(2) { [0]=> object(Closure)#92 (1) { ["parameter"]=> array(1) { ["$handler"]=> string(10) "" } } [1]=> string(12) "prepare_body" } } ["cached":"GuzzleHttp\HandlerStack":private]=> object(Closure)#101 (2) { ["static"]=> array(1) { ["handler"]=> object(GuzzleHttp\RedirectMiddleware)#100 (1) { ["nextHandler":"GuzzleHttp\RedirectMiddleware":private]=> object(Closure)#99 (2) { ["static"]=> array(1) { ["handler"]=> object(GuzzleHttp\PrepareBodyMiddleware)#96 (1) { ["nextHandler":"GuzzleHttp\PrepareBodyMiddleware":private]=> object(Closure)#88 (2) { ["static"]=> array(2) { ["default"]=> object(Closure)#86 (2) { ["static"]=> array(2) { ["default"]=> object(GuzzleHttp\Handler\CurlMultiHandler)#82 (5) { ["factory":"GuzzleHttp\Handler\CurlMultiHandler":private]=> object(GuzzleHttp\Handler\CurlFactory)#83 (2) { ["handles":"GuzzleHttp\Handler\CurlFactory":private]=> array(0) { } ["maxHandles":"GuzzleHttp\Handler\CurlFactory":private]=> int(50) } ["selectTimeout":"GuzzleHttp\Handler\CurlMultiHandler":private]=> int(1) ["active":"GuzzleHttp\Handler\CurlMultiHandler":private]=> NULL ["handles":"GuzzleHttp\Handler\CurlMultiHandler":private]=> array(0) { } ["delays":"GuzzleHttp\Handler\CurlMultiHandler":private]=> array(0) { } } ["sync"]=> object(GuzzleHttp\Handler\CurlHandler)#84 (1) { ["factory":"GuzzleHttp\Handler\CurlHandler":private]=> object(GuzzleHttp\Handler\CurlFactory)#85 (2) { ["handles":"GuzzleHttp\Handler\CurlFactory":private]=> array(1) { [0]=> resource(129) of type (curl) } ["maxHandles":"GuzzleHttp\Handler\CurlFactory":private]=> int(3) } } } ["parameter"]=> array(2) { ["$request"]=> string(10) "" ["$options"]=> string(10) "" } } ["streaming"]=> object(GuzzleHttp\Handler\StreamHandler)#87 (1) { ["lastHeaders":"GuzzleHttp\Handler\StreamHandler":private]=> array(0) { } } } ["parameter"]=> array(2) { ["$request"]=> string(10) "" ["$options"]=> string(10) "" } } } } ["parameter"]=> array(2) { ["$request"]=> string(10) "" ["$options"]=> string(10) "" } } } } ["parameter"]=> array(2) { ["$request"]=> string(10) "" ["$options"]=> string(10) "" } } } ["allow_redirects"]=> array(5) { ["max"]=> int(5) ["protocols"]=> array(2) { [0]=> string(4) "http" [1]=> string(5) "https" } ["strict"]=> bool(false) ["referer"]=> bool(false) ["track_redirects"]=> bool(false) } ["http_errors"]=> bool(true) ["decode_content"]=> bool(true) ["verify"]=> bool(true) ["cookies"]=> bool(false) ["headers"]=> array(1) { ["User-Agent"]=> string(38) "GuzzleHttp/6.2.1 curl/7.51.0 PHP/7.1.1" } } } }
And $lat and $lng is only null... I dont know whats happens... Dont receive response in lookup()
If I do not add the google key in the application parameters, dump_var is KEY = null
I kept looking at the file ClientAbstrac () and it's different here from the Master, probably my composer downloaded an earlier version ... I'm trying to fix it ..
googleMapsApiKey
<-- you sed this parameter name?
'googleMapsApiKey' => 'AIzaSyCT4r6gm0Cqy4s1ccr0vYk7wuVQhqi558M'
I test in localhost.. Its a problem?
Maps and DirectionsRequest is working perfectly...
But I need Geocoding...
I'll review @SereiaMaster, give me a couple of hours as I am currently working 🗡
Of course! Thank you very much for your attention! @tonydspaniard
@SereiaMaster I have just tested and it works:
public function actionTest()
{
$geo = new \dosamigos\google\maps\services\GeocodingClient();
$geo->params['key'] = 'AIzaSyCT4r6gm0Cqy4s1ccr0vYk7wuVQhqi558M';
$results = $geo->lookup(['address' => 'Stationsplein, 1012 AB Amsterdam, Netheterlands']);
print_r(json_encode($results));
}
Results:
{
"results": [{
"address_components": [{
"long_name": "Stationsplein",
"short_name": "Stationsplein",
"types": ["route"]
}, {
"long_name": "Centrum",
"short_name": "Centrum",
"types": ["political", "sublocality", "sublocality_level_1"]
}, {
"long_name": "Amsterdam",
"short_name": "Amsterdam",
"types": ["locality", "political"]
}, {
"long_name": "Amsterdam",
"short_name": "Amsterdam",
"types": ["administrative_area_level_2", "political"]
}, {
"long_name": "Noord-Holland",
"short_name": "NH",
"types": ["administrative_area_level_1", "political"]
}, {
"long_name": "Netherlands",
"short_name": "NL",
"types": ["country", "political"]
}, {
"long_name": "1012",
"short_name": "1012",
"types": ["postal_code", "postal_code_prefix"]
}],
"formatted_address": "Stationsplein, 1012 Amsterdam, Netherlands",
"geometry": {
"bounds": {
"northeast": {
"lat": 52.38090529999999,
"lng": 4.903231
},
"southwest": {
"lat": 52.3773389,
"lng": 4.896131500000001
}
},
"location": {
"lat": 52.3786982,
"lng": 4.8989702
},
"location_type": "GEOMETRIC_CENTER",
"viewport": {
"northeast": {
"lat": 52.38090529999999,
"lng": 4.903231
},
"southwest": {
"lat": 52.3773389,
"lng": 4.896131500000001
}
}
},
"partial_match": true,
"place_id": "ChIJWfQoorcJxkcRd1YfhVZYN2s",
"types": ["route"]
}],
"status": "OK"
}
Even works like this:
public function actionTest()
{
$geo = new \dosamigos\google\maps\services\GeocodingClient();
$geo->params['key'] = 'AIzaSyCT4r6gm0Cqy4s1ccr0vYk7wuVQhqi558M';
$results = $geo->lookup(['address' => 'Stationsplein, 1012 AB Amsterdam', 'region' => 'Netherlands']);
print_r(json_encode($results));
}
Look... I do Maps and DirectionsRequest
Null in top image, is the return of your action,
I got it! The problem was that I did not have the CURL set up in xampp;
For those who have the same problem, can solve by this link: https://stackoverflow.com/questions/40502142/helloanalytics-guzzle-error-in-local
THANK YOU @tonydspaniard FOR ALL YOUR ATTENTION!
I admire your work! Congratulations!
I try use GeocondigClient but not return anything... look my code...
All var_dump is null...
I did the google test, using URL for lookup.. and works... my key access is all right.