alexpechkarev / google-maps

Collection of Google Maps API Web Services for Laravel
https://alexpechkarev.github.io/google-maps/
MIT License
523 stars 115 forks source link

header is not json #38

Closed mohammad6006 closed 6 years ago

mohammad6006 commented 6 years ago
$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

alexpechkarev commented 6 years ago

Hi @mohammad6006,

Thank you for your question.

The response from Google Maps API call, if not explicitly set, is json by default.

As per Laravel documentation, you would use following to return json response

return response()->json([ 'name' => 'Abigail', 'state' => 'CA' ]);

In your case use following:

$response = \GoogleMaps::load('geocoding')
        ->setParam (['address' =>'santa cruz'])
        ->get();

return response()->json([$response]);