Zeaun.com
  • Support
Zeaun.com
  • Support
Information Technology Mastery,

Getting Latitude and Longitude for a given Zip Code with PowerShell

by zupreme7 months agono comment
1
Shares
Share on FacebookShare on Twitter
ps9

Little do many know that PowerShell can be used for all kinds of behind-the-scenes data gathering operations. Any DevOps professional who is overlooking PowerShell as a built-into-Windows data gathering tool should take a second look.

In this example we are going to take a Zip code (I chose 28213 for the example), “feed” it to PowerShell, then return coordinates which could be useful in any number of subsequent operations, including mapping.

First, let’s assign the target ZIP code to a variable.

Assigning the target ZIP code to a variable

Next we will grab some data from a convenient API (Application Programming Interface). There are ALOT of open API’s which provide this kind of functionality. Even Google provides this, but using Google’s API is a bit more complex, especially once authentication becomes a factor.

Assigning the result to a variable

We now have some data stored within the $z variable, but what we actually want is “buried” within the object. Let’s extract that.

XML need not be learned here

Don’t worry about the formats shown. You do not need to learn XML for this tutorial. We are going deeper to the actual metadata.

Metadata related to the API response

This gives us more context regarding the data and its source, but it’s still not there data points we want. Let’s go deeper.

Not far now

We are getting closer. Now we can see the “location” element, which is what we actually want to access. Let’s go in.

Zeroing in on the Data Point

Great. We now have arrived at the “point” parameter, within which we will find the data we are looking for. It is worthy of note that our query to this API can include multiple zip codes and a range of the same, but that’s beyond the scope of today’s tutorial.

The data becomes apparent

And now we arrive at actual numerical data for Longitude and Latitude, with regard to our target Zip Code (28213, in this case).

Let’s assign those values to variables we can use later.

capture latitude and longitude in a single variable

Now, we could simply stop here and then we could reference $latlon.latitude and $latlon.longitude when we want to use these coordinates, but I prefer to keep things separate when optimal.

Assign latitude and longitude to separate variables

There. Now we have totally separate variables for our latitude and longitude values for the target zip code. From here you could push that data to any number of subsequent scripts, functions, or applications.

You now know how to pull coordinates for a given ZIP code using PowerShell. Please use this newfound power for Good instead of Evil.

-Z

Note: If you find this tutorial valuable, buy me coffee – https://cash.app/$Zeaun

Previous

Reading Reddit News via PowerShell

7 months ago
Next

Browsing NASA’s Image of The Day Archive using PowerShell

7 months ago

Leave a Reply Cancel reply

Related posts

pop1
Information Technology Mastery,

PowerShell Tutorial: Programmatically Retrieving the Population of each US State

by zupreme7 months agono comment
coin10
Information Technology Mastery,

Tutorial: Getting the current price of Bitcoin using Powershell (USD, EUR, & GBP)

by zupreme7 months agono comment
image-12
Information Technology Mastery,

Tutorial: Public IP Address Identification with PowerShell

by zupreme7 months agono comment
image-3
Information Technology Mastery,

Browsing NASA’s Image of The Day Archive using PowerShell

by zupreme7 months agono comment

© 2020 Zeaun Zarrieff. All rights reserved.