Location Search Feed allows textual queries across the location set. It also provides handy functionality to restrict by location type or parent ids. See examples for more information.
Location Search
For more information, browse the Location Search API
Request:
http://demosite.frommers.biz/frommers/location_search.feed?type=COUNTRY
Response:
<searchResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="feedschema/base.xsd" totalResultCount="7" currentPage="1" currentPageResultCount="7" totalPageCount="1" sort="name" sortDirection="ascending">
<locationResult id="143044" name="Australia" displayLocation="Australia" typeName="Country" type="COUNTRY" latitude="-25.2744" longitude="133.7751"/>
<locationResult id="143092" name="England" displayLocation="England" typeName="Country" type="COUNTRY"/>
<locationResult id="143101" name="France" displayLocation="France" typeName="Country" type="COUNTRY" latitude="46.2276" longitude="2.2137"/>
<locationResult id="143129" name="Italy" displayLocation="Italy" typeName="Country" type="COUNTRY" latitude="41.8719" longitude="12.5674"/>
<locationResult id="143131" name="Japan" displayLocation="Japan" typeName="Country" type="COUNTRY" latitude="36.2708" longitude="138.1512"/>
<locationResult id="143238" name="The Netherlands" displayLocation="The Netherlands" typeName="Country" type="COUNTRY" latitude="52.1326" longitude="5.2913"/>
<locationResult id="143254" name="USA" displayLocation="USA" typeName="Country" type="COUNTRY" latitude="39.9097" longitude="-101.2793"/>
</searchResponse> Call the feed URL, using curl
$ch = curl_init(); // Set up curl
curl_setopt($ch, CURLOPT_URL, $url); // Add url
curl_setopt($ch, CURLOPT_HEADER, 0); // Remove header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return data
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // Set timeout, 10s
$response = curl_exec($ch); // Call feed
curl_close($ch); // Close curl, free resources
Convert response to XML, use xpath to get list of locations
$xml = new SimpleXMLElement($response); // Create xml object
$locations = $xml->xpath("//locationResult"); //Use xpath to get list of locations
Build output dynamically by iterating location links
<div class="locationSearch">
<ul class="linkList">
<?php foreach ($locations as $location ) { ?>
<li><a href="#"><?php echo $location["name"];?></a></li>
<?php } ?>
</ul>
</div>
Loading...
