Reputation: 828
I am trying to set up the Trip-Advisor API to retrieve nearby hotels to a location name.In the documentation listed below is shows you how to get location by ID, which I have set up and is successfully working using the link below.
$apiRequest = "http://api.tripadvisor.com/api/partner/2.0/location/60745/hotels?key=".$key
Now I need a similar result but searching off names not location ID. This way I can put an input field where a user types in location name and searches. In the documentation (linked below) it mentions location name near the bottom of the page but I can't seem to implement it. I think I may be misinterpreting it being new to API's
https://developer-tripadvisor.com/content-api/documentation/location/
I have tried replacing ID with a location name but as expected this fails.
I have also tried placing location-name into it with a parameter URL - /location-name/manchester/ - URL
I will post updates with attempts as I do them,
Thanks
Upvotes: 2
Views: 8787
Reputation: 104
Unfortunately, Trip Advisor doesn't offer a way to convert a search string into location IDs. However, Trip Advisor allows you to search by lat/lon for nearby results with the map/ endpoint. In the response there will be a "Ancestors" object that will look something like this:
"ancestors": [
{
"abbrv": null,
"level": "City",
"name": "Boston",
"location_id": "60745"
},
{
"abbrv": "MA",
"level": "State",
"name": "Massachusetts",
"location_id": "28942"
},
{
"abbrv": null,
"level": "Country",
"name": "United States",
"location_id": "191"
}
],
"bearing": "north",
"longitude": "-71.09922",
"rating": null,
"latitude": "42.33227",
"ranking_data": null
}
As you can see this contains the location IDs of the city and state. With this information, you can grab the user's search query, convert that to lat/lons (Google Geocoding Api), hit the Trip Advisor Api Map endpoint, get the city Location ID, then use that to search nearby hotels.
Clearly, this is very roundabout and requires 3 separate api calls, but this is the only programmatic way to resolve a search query into location IDs. (Much better than the proposed manual ID collection method in my opinion)
Upvotes: 4
Reputation: 5716
A destination (or geo) is geographic location. This can be a country, state, province, region or city. You can identify a geo location ID on TripAdvisor by navigating to that destination’s page and looking for the number after the ‘g’ parameter in the URL. For example, the geo location ID for the city of Boston is 60745, as defined in the URL below:
http://www.tripadvisor.com/Tourism-g60745-Boston_Massachusetts-Vacations.html
POIs include accommodations, attractions and restaurants that are listed and can be reviewed on TripAdvisor. You can find the location ID for a TripAdvisor POI by navigating to the property’s page on TripAdvisor and looking for the number after the ‘d’ parameter in the URL. For example, the location ID for the Hotel Commonwealth in Boston is 258705.
Note that the URL for a POI also includes the geo location ID for the city in which it’s located (after the ‘g’).
Location ID Mapping
TripAdvisor does not support any services to its Content API users for mapping partner or external location IDs to TripAdvisor location IDs for destinations or POIs.
Read: http://developer-tripadvisor.com/content-api/locations/
Upvotes: 3