Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

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

$
0
0
I used my API key for querying google places API for obtaining museums around a particular place and obtained the following results in JSON form:
{
   "html_attributions" : [],
   "results" : [
      {
         "geometry" : {
            "location" : {
               "lat" : 15.4954990,
               "lng" : 73.82120
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/museum-71.png",
         "id" : "1f1425a4048b951552591838918fddcfa92ce0a9",
         "name" : "Museum",
         "reference" : "CpQBgQAAABj0cBhH-lN_qR75O8cH-CaRqZxZyY98edwHytsuW3hEgA9YX0L9Q5lNSxxJkWKc4hQWZaBie4rAxF6toH1gfcF-EH-8aidpfccqXH7Y6UyN06gNRtaMZtX4KdoQfoDrMvcLPxlpC519Aa6ZFBWII7agaGJ8x3-4Bi7PDIH3nqe6h7ywvQFI12sXh80VE7DhuhIQ-vAeCJylozUNoeZdYEIvLRoUYjxWFbm08-HG-7RIt1JBNcCOsyI",
         "types" : [ "museum", "establishment" ],
         "vicinity" : "Althino, Panaji (Panjim)"
      }
   ],
   "status" : "OK"
}


Then I wrote the following code to obtain only certain data from the JSON result i.e name,type,vicinity

<?php

$details_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, $details_url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   $geoloc = json_decode(curl_exec($ch), true);

  $name=var_dump($geoloc['results'][0]['geometry']['name']);
$types=var_dump($geoloc['results'][0]['geometry']['types']);
$vicinity=var_dump($geoloc['results'][0]['geometry']['types']);


   print $name;
   print $types;
     print $vicinity;

?>  



But it shows error. I have made changes to the following files in WAMP to enable the curl extension(by removing ;)/>

wamp\bin\php\(your php version)\php.ini

wamp\bin\Apache\(apache version)\bin\php.ini

but I am still getting an error when i run the php file with the curl functions. Please help me figure out what i'm doing wrong here.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>