DEV Community

Jordan Hansen
Jordan Hansen

Posted on • Originally published at javascriptwebscrapingguy.com on

Jordan Uses positionstack

Demo code here

This is a sponsored blog post by positionstack. All reviews and opinions expressed here are, however, based on my personal experience.

This is my third post about APIs created by apilayer. The other two were for scrapestack (for proxying any and all web requests) and serpstack (for getting search engine results in a quick and easy JSON format). I’ve really been impressed with the speed and ease of all of their products and positionstack is no exception, with full featured documentation on their product here.

Free text address query

funny gif about query
query. get it?

The bread and butter of positionstack and what makes it especially easy to use is that it accepts free text queries. I tried multiple addresses and partial addresses, including my local walmart:

    const baseUrl = `http://api.positionstack.com/v1`;

    // Local Walmart
    const query = '5001 N Ten';

    const axiosResponse = await axios.get(`${baseUrl}/forward?access_key=${process.env.apiKey}&query=${query}&limit=1`);

    console.log("axiosResponse.data", axiosResponse.data);
Enter fullscreen mode Exit fullscreen mode

To which the response was very easily and quickly:

positionstack results for local walmart

Very simple and super useful for when you want to verify an address. When web scraping I often find myself with something that I’m not quite sure is an address. There are a lot of different ways to format an address and so being able to take a small part of that address and convert it to a full one is INCREDIBLY useful.

For Cobalt Intelligence we are often trying to verify just the region, typically city and state. Let’s try something that we are pretty sure is a city but we aren’t quite sure where the city is located. Morrisville, in this example:

    const baseUrl = `http://api.positionstack.com/v1`;

    // Local Walmart
    const query = 'morrisville';

    const axiosResponse = await axios.get(`${baseUrl}/forward?access_key=${process.env.apiKey}&query=${query}&limit=1`);

    console.log("axiosResponse.data", axiosResponse.data);
Enter fullscreen mode Exit fullscreen mode

And the results?

positionstack results for morrisville

A city in North Carolina, USA. VERIFIED!

More features!

All of the above is enough to make positionstack an awesome tool. But there are a lot more features that make it AMAZING.

How about timezone? Positionstack includes a module for that. Just pass a timezone_module=1 flag and it returns an additional object with the timezone of the location. Check it based on a church I used to frequent in Brazil:

    // Church in Brazil
    const query = 'Rua 9 A 199';

    const axiosResponse = await axios.get(`${baseUrl}/forward?access_key=${process.env.apiKey}&query=${query}&limit=1&timezone_module=1`);

    console.log("axiosResponse.data", axiosResponse.data, axiosResponse.data.data[0].timezone_module);
Enter fullscreen mode Exit fullscreen mode

And the result?

positionstack results for timezone module

Check that timezone_module at the bottom. She’s a beaut.

Image result for she's a beaut clark

Another kind of neat module is the sun module, showing the rise and set time.

    // Local Walmart
    const query = '5001 N Ten';

    // sun module   
    const axiosResponse = await axios.get(`${baseUrl}/forward?access_key=${process.env.apiKey}&query=${query}&limit=1&sun_module=1`);

    console.log("axiosResponse.data", axiosResponse.data, new Date(axiosResponse.data.data[0].sun_module.rise.time * 1000));
Enter fullscreen mode Exit fullscreen mode

Based on the above query, the sun will rise at 8:14am this morning where I am. Or at least, where my local walmart is.

positionstack results for sun module

And finally, a country module with a TON of information. I’m going to try it with our Brazilian address.

    // Church in Brazil
    const query = 'Rua 9 A 199';

    // country module
    const axiosResponse = await axios.get(`${baseUrl}/forward?access_key=${process.env.apiKey}&query=${query}&limit=1&country_module=1`);

    console.log("axiosResponse.data", axiosResponse.data, axiosResponse.data.data[0].country_module);
Enter fullscreen mode Exit fullscreen mode

The results of this returns:

positionstack results for country_module

Full details about the country, including language and even if the country is landlocked. In case you wanted to know that as well.

Em fim

the end gif

Pricing for positionstack is very reasonable, with 25,000 requests a month allowed in their free plan. Check out the full pricing here. Currently it looks like this:

positionstack pricing

Overall, great product. Very fun and easy to use.

The post Jordan Uses positionstack appeared first on JavaScript Web Scraping Guy.

Top comments (0)