Skip to main content
APIs 5 min read

Solutions: Day 31-35 #100DaysOfCode

Solutions: Day 31-35 #100DaysOfCode

We are back with another week of #100DaysOfCode with HERE. If you have no idea what I'm talking about, take a look at this blog post which will tell you everything about #100DaysOfCode. In this blog post, I will cover solutions for days 31 through 35. If you have missed the solutions for days 0-30, you can read them in my previous blogs posts or in the video format.

Let's begin!

Day 31/100

With Day 31, we start exploring the browse endpoints of the Geocoding and Search API. While the discover endpoint lets you do a free form search for points of interest, the browse endpoint lets you perform a more structured search. For day 31 we will do a simple search with name

Copied
        
    // Get an instance of the geocoding service:
    var geocoder = platform.getSearchService();
  
    function geocodeAndSearch(){
  
        let geocoderParams = {
            name: 'museum',
            at : '52.45722,13.38044'
        }
  
        function onResult(result){
          console.log(result);
        }
  
        geocoder.browse(geocoderParams,onResult,alert);
  
    }
  
    geocodeAndSearch();

  

Day 32/100

The points of interests or 'Places' in the HERE database have been arranged in different categories with 3 levels of granularity. Level 1 is the logical high-level grouping with category names like 'Eat and Drink' or 'Landmark-Attraction'. Level 2 is the sub-group where 'Eat and Drink' is further divided into categories like 'Restaurants'. Level 3 further categorizes these sub-groups such as 'Eat and Drink - Restaurants - Casual Dining'. For day 32, we will use a level 2 category description to look for 'History Museums' around us. We will thus use the category 300-3100-0028 to search for 'History Museum'.

Copied
        
    // Get an instance of the geocoding service:
    var geocoder = platform.getSearchService();
  
    function geocodeAndSearch(){
  
        let geocoderParams = {
            name: 'museum',
            at : '52.45722,13.38044',
            categories: '300-3100-0028'
        }
  
        function onResult(result){
          console.log(result);
        }
  
        geocoder.browse(geocoderParams,onResult,alert);
  
    }
  
    geocodeAndSearch();

  

Day 33/100

Along with a places category system, HERE also offers a food category system. One of the reasons I work with this company is because they take their food as seriously as I do! With the food categories, you can go as specific to search for different cuisines of places that offer food. For day 33, we will combine the food category and places category to look for places which serve 'Mexican food' and have a 'take-out service'. Thus we will use a combination of categories 100-1000-0003 for 'Eat and Drink - Restaurants - Take Out and Delivery Only' and 102-000 for 'North American - Mexican'.

Copied
        
    // Get an instance of the geocoding service:
    var geocoder = platform.getSearchService();
  
    function geocodeAndSearch(){
  
        let geocoderParams = {
            name: 'restaurant',
            at : '52.45722,13.38044',
            categories: '102-000,100-1000-0003'
        }
  
        function onResult(result){
          console.log(result);
        }
  
        geocoder.browse(geocoderParams,onResult,alert);
  
    }
  
    geocodeAndSearch();

  

Day 34/100

While you can do a search with names and categories, you can also do a table lookup if you know the id of a place. Take a look at one of the the results from the query from day 33 or any autosuggest results. In the result returned, you will find a property called id.

Copied
        
{…}
    access: Array [ {…} ]
    address: Object { label: "Que Pasa, Zossener Straße 27, 10961 Berlin, Deutschland", countryCode: "DEU", countryName: "Deutschland", … }
    ​categories: Array [ {…} ]
    ​​​contacts: Array [ {…} ]
    ​​distance: 3683
    ​​​foodTypes: Array [ {…}, {…} ]
    ​​​id: "here:pds:place:276aabd1-9fd829e3684d05b86f7ddb1f3f83924c" 
    ​​​openingHours: Array [ {…} ]
    ​​​position: Object { lat: 52.48935, lng: 13.39362 }
    ​​​resultType: "place"
    ​​​title: "Que Pasa"

  

For day 34, we use this id with the lookup endpoint to search for the specific place.

Copied
        
// Get an instance of the geocoding service:
var geocoder = platform.getSearchService();

function geocodeAndSearch(){

    let geocoderParams = {
        id : 'here:pds:place:276aabd1-9fd829e3684d05b86f7ddb1f3f83924c'
    }

    function onResult(result){
        console.log(result);
    }

    geocoder.lookup(geocoderParams,onResult,alert);

}

geocodeAndSearch();

  

Day 35/100

During days 21 to 34 we performed what we call forward searches, where you search for places with names or categories and get their location in the form of a latitude and longitude. In a situation where you know the location of a place and want to know what it is called, you will have to use something called a reverse geocoder. As the name suggests, you need to pass the location of this place and in return, you get the complete address with other fields as a result.

Copied
        
// Get an instance of the geocoding service:
var geocoder = platform.getSearchService();

function geocodeAndSearch(){

    let geocoderParams = {
        at : '52.5415,13.39316'
    }

    function onResult(result){
        console.log(result);
    }

    geocoder.reverseGeocode(geocoderParams,onResult,alert);

}

geocodeAndSearch();

  

This week we covered the explore, lookup and reverse geocoder endpoints of the Geocoding and Search on #100DaysOfCode. Next week, we will take look at 'Geofencing' in #100DaysOfCode. Keep following us on Twitter for more tasks and complete all 100 days. If you want to watch the video version of these solutions, take a look at our playlist for #100DaysOfCode on YouTube.

While you're at it, why don't you take a look at Ray's recent Star Wars blog post.

To get a step-by-step guide to use HERE OAuth with Python, head over to the detailed tutorial by our very own 🥑 Vidhan.

Happy coding!

Shruti Kuber

Shruti Kuber

Have your say

Sign up for our newsletter

Why sign up:

  • Latest offers and discounts
  • Tailored content delivered weekly
  • Exclusive events
  • One click to unsubscribe