Skip to content

Instantly share code, notes, and snippets.

@g2384
Created April 9, 2014 11:53
Show Gist options
  • Save g2384/10260113 to your computer and use it in GitHub Desktop.
Save g2384/10260113 to your computer and use it in GitHub Desktop.
<?
function k($word, $api)
{
$str = file_get_contents("https://maps.googleapis.com/maps/api/place/textsearch/xml?query=$word&sensor=true&key=$api");
$obj = simplexml_load_string($str, 'SimpleXMLElement', LIBXML_NOCDATA);
$result = $obj->result;
$n = count($result);
for ($c = 0; $c < $n; $c++) {
$printOut = "";
$printOut = $printOut . "Name: " . $result[$c]->name . "<br>";
$typeLen = count($result[$c]->type);
$typeStr = "";
for ($d = 0; $d < $typeLen; $d++) {
$typeStr = $typeStr . $result[$c]->type[$d] . " / ";
}
$typeStr = substr($typeStr, 0, -3);
$printOut = $printOut . "Type: " . $typeStr . "<br>";
$printOut = $printOut . "Addr: " . $result[$c]->formatted_address . "<br>";
$printOut = $printOut . "Rating: " . $result[$c]->rating . "<br>";
$printOut = $printOut . "Price level: " . ($result[$c]->price_level == "" ? "Not available" : $result[$c]->price_level) . "<br>";
$reference = $result[$c]->reference;
$str2 = file_get_contents("https://maps.googleapis.com/maps/api/place/details/xml?reference=$reference&sensor=false&key=$api");
$obj2 = simplexml_load_string($str2, 'SimpleXMLElement', LIBXML_NOCDATA);
$printOut = $printOut . "Telephone: " . $obj2->result->formatted_phone_number . "<br>";
$printOut .= "<br>";
echo $printOut;
}
echo "<hr>All information can be found on <a href=\"https://developers.google.com/places/documentation/\">https://developers.google.com/places/documentation/</a><hr> More information [use 'view page source' to chech the list]: <br>";
print_r($obj);
}
k($_SERVER['QUERY_STRING'], "YourAPIKeyHere");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment