how to use curl in php for json results from google places api

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 2937 Views - Last Post: 12 January 2013 - 04:05 PM Rate Topic: -----

#16 nainas9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 22-December 12

Re: how to use curl in php for json results from google places api

Posted 12 January 2013 - 03:46 PM

View PostDormilich, on 12 January 2013 - 03:41 PM, said:

it would be more interesting to know, what curl_exec() returned.

In this case null i guess. I can't figure out why.
Was This Post Helpful? 0
  • +
  • -

#17 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3485
  • View blog
  • Posts: 10,045
  • Joined: 08-June 10

Re: how to use curl in php for json results from google places api

Posted 12 January 2013 - 03:47 PM

wouldn’t it be better to test instead of guessing?
Was This Post Helpful? 0
  • +
  • -

#18 nainas9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 22-December 12

Re: how to use curl in php for json results from google places api

Posted 12 January 2013 - 03:54 PM

View Postnainas9, on 12 January 2013 - 03:50 PM, said:

View PostDormilich, on 12 January 2013 - 03:41 PM, said:

it would be more interesting to know, what curl_exec() returned.

In this case it returns null i guess. i can't figure out why.

Yes i did. I executed the file in WAMP and all it showed was
null
null
null
Please help. I am stuck.


Am i writing the curl functions incorrectly? I know the code is the problem. What would you do if you were in my position right now?

This post has been edited by Dormilich: 12 January 2013 - 03:56 PM

Was This Post Helpful? 0
  • +
  • -

#19 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3485
  • View blog
  • Posts: 10,045
  • Joined: 08-June 10

Re: how to use curl in php for json results from google places api

Posted 12 January 2013 - 03:55 PM

but that’s not the dump of curl_exec() that I asked for.

it might also help to fire up error reporting and error display.

Quote

What would you do if you were in my position right now?

test what curl_exec() returns, because that’s the source of your data.

This post has been edited by Dormilich: 12 January 2013 - 03:56 PM

Was This Post Helpful? 0
  • +
  • -

#20 nainas9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 22-December 12

Re: how to use curl in php for json results from google places api

Posted 12 January 2013 - 04:05 PM

View PostDormilich, on 12 January 2013 - 03:55 PM, said:

but that’s not the dump of curl_exec() that I asked for.

it might also help to fire up error reporting and error display.

Quote

What would you do if you were in my position right now?

test what curl_exec() returns, because that’s the source of your data.

Thanks man!! u rock!!
i got it!
i modified the code

<?php
$url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=15.495602,73.825209&radius=500&types=museum&sensor=false&key=AIzaSyDqEa1fnjGtG4QdAiaekCHKV_tDaN4Nuxo";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$response_a = json_decode($response);
echo $name = $response_a->results[0]->name;
echo "<br />";
echo $vicinity = $response_a->results[0]->vicinity;
?>



and got the output as
Museum
Althino, Panaji (Panjim)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2