//These code snippets are ajax calls made using the jQuery 1.6 library (http://www.jquery.com).
//Get categories - this will add all the categories to a list and display them on a page.
var categories="";
$.ajax({
type: "GET",
url: "http://api.pearson.com/eyewitness/london/categories.json",
data: "apikey="+apiKey,
dataType: "jsonp",
success: function(data){
categories +="<ul>";
for(i=0; i < data.categories.category.length; i++){
categories+= "<li>" + data.categories.category[i]['#text']+"</li>";
}
categories +="</ul>";
document.write(categoryArray );
}
});
/******* To have more readable category names use the switch statement below in the for loop to use a different name ********/
switch([RETURNED CATEGORY NAME]){
case "Ceremonies":
categoryShortName = "Ceremonies";
break;
case "Museums":
categoryShortName = "Museums";
break;
case "Gardens_Parks_And_Squares":
categoryShortName = "Green Space"
break;
case "Historic_London_Homes":
categoryShortName = "Great Homes"
break;
case "Restaurants":
categoryShortName = "Restaurants"
break;
case "Theatre":
categoryShortName = "Theatre"
break;
case "Light_Meals_And_Snacks":
categoryShortName = "Snacks"
break;
case "Childrens_London":
categoryShortName = "Childrens"
break;
case "Clubs":
categoryShortName = "Clubs"
break;
case "Pubs_And_Bars":
categoryShortName = "Pubs/Bars"
break;
case "Hotels":
categoryShortName = "Hotels"
break;
case "Music":
categoryShortName = "Music"
break;
case "Churches":
categoryShortName = "Churches"
break;
case "Sport_And_Fitness":
categoryShortName = "Sports"
break;
case "Shops":
categoryShortName = "Shops"
break;
case "Cinema":
categoryShortName = "Cinema"
break;
case "Markets":
categoryShortName = "Markets"
break;
}
//Search for geolocated attractions around current location and assign relevant information to a
$.ajax({
type: "GET",
url: "http://api.pearson.com/eyewitness/london/block.json",
data: "tag=tg_info&apikey="+apiKey+"&lat="+[currentLatitude]+"&lon="+[currentLongitde],
dataType: "jsonp",
success: function(data){
for(i=0; i < data.list.link.length; i++){
var title = data.list.link[i]["@title"];
var latitude = data.list.link[i]["@latitude"];
var longitude = data.list.link[i]["@longitude "];
var dkid = data.list.link[i]["@id"];
var parentID = data.list.link[i]["@parent"];
var category = data.list.link[i]["@category"];
}
});
//Search for attractions that are in the Museums or Hotels category
$.ajax({
type: "GET",
url: "http://api.pearson.com/eyewitness/london/block.json",
data: "apikey="+apiKey+"&category=Museums,Hotels",
dataType: "jsonp",
success: function(data){
for(i=0; i < data.list.link.length; i++){
var title = data.list.link[i]["@title"];
var latitude = data.list.link[i]["@latitude"];
var longitude = data.list.link[i]["@longitude "];
var dkid = data.list.link[i]["@id"];
var parentID = data.list.link[i]["@parent"];
var category = data.list.link[i]["@category"];
}
});
/*GETTING INFORMATION BACK ABOUT A SPECIFIC ATTRACTION
The best way to get text for an attraction:
Search for [articles/entries] in category you're attraction is in. Loop through the results and match titles with the desired title.
Blocks with the role 'catalogue' or 'listing_entry' have the text in the top level of the response.
Blocks with the rold 'star_sight' will have text inside an intro block.
All text will have key of 'p'. Stripping out HTML from the text is advisable as there are some scenarios where certain HTML tags are used.
Any blocks with the role 'dir_entry' do not have any text associated with that attraction.
Finding images is best done in a similar fashion. Search the category for illustrations and then match titles with the attraction you are looking for.
*/






