Tips & Tricks: Automatically generate code snippets using the HERE Maps API Explorer

30 October 2015

You probably know that you can use the HERE REST API Explorer to help you create and test your REST API calls. You probably also know that the API Explorer has several neat features, like the ability to view and set parameters such as latitude and longitude on an interactive map. For example, if you want to calculate a route, you can simply click on the waypoint0 parameter in the explorer and then drag the reticle to your desired starting location. The correct latitude and longitude will then automatically be generated for that parameter.

Clicking on a waypoint parameter allows you to select the location on a map

What you may not know however, is that you can also use the API Explorer to automatically generate cURL commands, code snippets in jQuery and code snippets for our Maps API for JavaScript. This useful feature is hiding behind the "View Code" button in the upper right corner. Click this button and you will get three options to generate your code: "as cURL command", "as jQuery code snippet" and "as Maps API for JavaScript code snippet".

Select the View Code button to generate code snippets

The results will show up on the page right above the Response area. For example, if you wanted to calculate a route from the Fernsehturm to the Kurfürstendamm in Berlin using public transport, the API Explorer would generate the following cURL command using the "View Code" feature.

If you're using jQuery, it can also generate the following jQuery code snippet.

Finally, the code snippet for the HERE Maps API for JavaScript would look like this:

Remember that you need to replace {YOUR_APP_CODE} and {YOUR_APP_ID} with your own code and ID for all of these examples. You can get these by signing up for your free trial at developer.here.com .




top