Using PHP (curl) to pull data from JSON (Google Maps API)

后端 未结 2 1427
清酒与你
清酒与你 2020-12-23 17:31

I\'m fairly new to JSON, and I\'m trying to get the latitude and longitude of a geocoded city from the Google Maps API using curl. The function I\'m using is:



        
2条回答
  •  余生分开走
    2020-12-23 18:21

    You just need this :

    $fullurl = "http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true";
    $string .= file_get_contents($fullurl); // get json content
    $json_a = json_decode($string, true); //json decoder
    
    echo $json_a['results'][0]['geometry']['location']['lat']; // get lat for json
    echo $json_a['results'][0]['geometry']['location']['lng']; // get ing for json
    

提交回复
热议问题