<?php /** * show_address * * Given an address, show the location on a map. * * @version 0.6 * @author Contributors at eXorithm * @link /algorithm/view/show_address Listing at eXorithm * @link /algorithm/history/show_address History at eXorithm * @license /home/show/license * * @param mixed $address The address to find. * @return array latitude/longitude */ function show_address($address='The White House 1600 Pennsylvania Ave NW Washington, DC 20500') { $data = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=".urlencode($address)."&sensor=false"); $obj = json_decode($data); if ($obj) { if (isset($obj->results[0]->geometry->location)) { $loc = $obj->results[0]->geometry->location; return array('latitude'=>$loc->lat, 'longitude'=>$loc->lng); } else { throw new Exception('Lookup failed and/or address does not exist!'); } } else { throw new Exception('Lookup failed and/or address does not exist!'); } } ?>