user3043636
user3043636

Reputation: 579

Reverse Geocoding in PHP request

I would like to Reverse Geocoding (from GPS coordinates to addresses) and I have a http request from Google Api and is :

 $StringaCo= file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?latlng='. $x . ', '.$y.'&sensor=false&location_type=ROOFTOP&result_type=street_address&key=AIzaSyDX7vrxKQI2cHWLS7aghb1ORv1dRX_yQSk');

and I process this http request with :

$StringL= json_decode($StringaCo);

now I want to print all with :

print_r($StringL);

but I received this error :

Warning : file_get_contents(https://maps.googleapis.com/maps/api/geocode/json?latlng=41.805931099999995, 12.432546499999999&sensor=false&location_type=ROOFTOP&result_type=street_address&key=AIzaSyDX7vrxKQI2cHWLS7aghb1ORv1dRX_yQSk): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request.

Could someone, please, help me?

Upvotes: 1

Views: 1530

Answers (1)

Ming M Zheng
Ming M Zheng

Reputation: 304

change:

$StringaCo= file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?latlng='.$x.', '.$y.'&sensor=false&location_type=ROOFTOP&result_type=street_address&key=AIzaSyDX7vrxKQI2cHWLS7aghb1ORv1dRX_yQSk');

to:

$StringaCo= file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?latlng='. $x.','.$y.'&sensor=false&location_type=ROOFTOP&result_type=street_address&key=AIzaSyDX7vrxKQI2cHWLS7aghb1ORv1dRX_yQSk');

you need remove extra space after comma

Upvotes: 1

Related Questions