How to rate Points Of Interest automatically

api, development, google, ideas Add comments

During my work on sunnyrentals.com I’ve got a task to add 2 closest airports to every property an owner creates.

I implemented it quite fast since we have a database of airports with coordinates.

While playing with this feature, we found out that it is not good enough — the real task must be to add 2 closest and biggest airports. The problem is that we don’t have any data in airports DB to guess how big or famous a particular airport is.

So we need to rate every airport somehow…

The solution we found was simple — we need to google for the airport name and get the search results count. The count can be considered as rating value — London Heathrow airport has 2.33 million results while Kiev Zhulyany airport has only 0.77 mln which looks fair.

Several things to pay attention to:

  • the query we formed was [city name] + [airport name] + ‘ airport’
  • if this query gives zero result, I omit the city name — at times it hepls
  • we put the query into quotes to google for the exact phrase, otherwise the London City airport gets the highest rating due to the fact that “city” is a general term
  • if the airport name includes the city name (Melbourne Intl), we omit the city name — “Melbourne Intl airport” is better then “Melbourne Melbourne Intl airport
  • in addition to previous idea — if the airport name sounds like the city name, we omit the city name as well. Example: Narsarsuaq airport in Narssarssuaq city. I used soundex function for this comparison — it’s present in PHP and MySQL.

To get the google results you can use the Google Search API:

$queryTemplate = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=%s';
$airportQuery = '"London Heathrow airport"';
$query = sprintf( $queryTemplate, urlencode( $airportQuery ) );
$json = json_decode( file_get_contents( $query ), 1 );
$rating = (int)$json['responseData']['cursor']['estimatedResultCount'];

Comments are closed.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in