Jordan Uses positionstack
Tags: apilayer, geocoding, javascript, location
Published: 2019-12-28 18:26:39

---
title: Jordan Uses positionstack
published: true
date: 2019-12-23 14:53:09 UTC
tags: apilayer,geocoding,Javascript,location
canonical_url: https://javascriptwebscrapingguy.com/jordan-uses-positionstack/
---

[Demo code here](https://github.com/aarmora/jordan-uses-positionstack)

_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](https://apilayer.com/). The other two were for [scrapestack](https://javascriptwebscrapingguy.com/jordan-scrapes-with-scrapestack/) (for proxying any and all web requests) and [serpstack](https://javascriptwebscrapingguy.com/serpstack-easy-search-engine-results/) (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](https://positionstack.com/documentation).

## Free text address query

![funny gif about query](https://media.giphy.com/media/QZnRI8keM8k1Z7cUur/giphy.gif)<figcaption>query. get it?</figcaption>

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);
```

To which the response was very easily and quickly:

![positionstack results for local walmart](https://javascriptwebscrapingguy.com/wp-content/uploads/2019/12/image.png)

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](https://cobaltintelligence.com) 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);
```

And the results?

![positionstack results for morrisville](https://javascriptwebscrapingguy.com/wp-content/uploads/2019/12/image-1.png)

A city in North Carolina, USA. VERIFIED!

## More features!

![](https://media.giphy.com/media/6Nm4HEzQVtEis/giphy.gif)

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);
```

And the result?

![positionstack results for timezone module](https://javascriptwebscrapingguy.com/wp-content/uploads/2019/12/image-2.png)

Check that timezone\_module at the bottom. She’s a beaut.

![Image result for she's a beaut clark](https://i.imgflip.com/2cveh8.jpg)

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));
```

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](https://javascriptwebscrapingguy.com/wp-content/uploads/2019/12/image-3.png)

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);
```

The results of this returns:

![positionstack results for country_module](https://javascriptwebscrapingguy.com/wp-content/uploads/2019/12/image-4.png)

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](https://media.giphy.com/media/l1Lc1Kn9hImgpx5Re/giphy.gif)

Pricing for positionstack is very reasonable, with 25,000 requests a month allowed in their free plan. Check out the full pricing [here](https://positionstack.com/product). Currently it looks like this:

![positionstack pricing](https://javascriptwebscrapingguy.com/wp-content/uploads/2019/12/image-5-1024x696.png)

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

The post [Jordan Uses positionstack](https://javascriptwebscrapingguy.com/jordan-uses-positionstack/) appeared first on [JavaScript Web Scraping Guy](https://javascriptwebscrapingguy.com).