javascriptgeolocationgeocodinghere-apihere-maps-rest

How to search HERE API for POI's by address, city, country, etc.?


I am having trouble finding documentation or an example covering how to search for POI's within a certain radius of an address or location. So far, all I have seen is searching by latitude or longitude, which is not feasible in my use case.

The idea is a pretty standard one: a user enters a location (address, zip code, city, country, etc.) which leads to a call to the HERE API searching for a point of interest near the location that was entered. Perhaps within a certain radius.

Does anyone know how to use the HERE API to search by location, not coordinates? These are the dosc I am using: https://developer.here.com/documentation.


Solution

  • That's typical from location APIs to work with coordinates. For example, the Discover endpoint from HERE Geocoding & Search API v7 requires you to pass one of at, in:bbox or in:circle parameters, all of them working with coordinates.

    What you need to do is to first convert your address to coordinates, by calling the Geocode endpoint.

    example of Geocoding using curl

    curl --location --request GET 'https://geocode.search.hereapi.com/v1/geocode?limit=20&q=2609 University Ave, Austin, TX 78712&apiKey=YOUR_API_KEY'
    

    The above request returns the following response:

    {
        "items": [
            {
                "title": "2609 University Ave, Austin, TX 78712-1057, United States",
                "id": "here:af:streetsection:ihOI0ch5OPr-Y1e1m65IRC:CgcIBCDKhfpLEAEaBDI2MDk",
                "resultType": "houseNumber",
                "houseNumberType": "PA",
                "address": {
                    "label": "2609 University Ave, Austin, TX 78712-1057, United States",
                    "countryCode": "USA",
                    "countryName": "United States",
                    "stateCode": "TX",
                    "state": "Texas",
                    "county": "Travis",
                    "city": "Austin",
                    "district": "University of Texas - Austin",
                    "street": "University Ave",
                    "postalCode": "78712-1057",
                    "houseNumber": "2609"
                },
                "position": {
                    "lat": 30.29009,
                    "lng": -97.73891
                },
                "access": [
                    {
                        "lat": 30.29009,
                        "lng": -97.73906
                    }
                ],
                "mapView": {
                    "west": -97.73995,
                    "south": 30.28919,
                    "east": -97.73787,
                    "north": 30.29099
                },
                "scoring": {
                    "queryScore": 1.0,
                    "fieldScore": {
                        "state": 1.0,
                        "city": 1.0,
                        "streets": [
                            1.0
                        ],
                        "houseNumber": 1.0,
                        "postalCode": 1.0
                    }
                }
            }
        ]
    }
    

    Then use the coordinates returned by the position property of a response item to find Point of Interests around that location.