Custom Google Maps Geocode Powershell CmdLet

by Donn Felker 18. September 2008 09:43

This may look like a repeat... well.. because it is... BUT.. you cannot find the old post. Why? Because, well ... it no longer exists. My old host decided to accidentally delete my account. Yeah. Oops. After that nightmare, I've moved to a new host where the grass is greener, the hippies wear deodorant and well ... wait ... never mind... onto the good stuff...Here's the old post, reposted again.

---------------------------------

Ok, I admit ... I have a fascination with maps. Why? Who knows. I just love knowing where I'm at, where I'm going, not being lost, etc etc etc. Last year I wrote a C# class that would connect to Google Maps and return the latitude and longitude of an address by utilizing the Google Maps API. Get that class

Awhile back I also wrote about the complexity of our industry and about how staying up to speed is quite difficult. Jeffrey Snover (PowerShel/Windows Management Architect) commented on that post and recommend learning PowerShell. I completely agree with what he said. However - I've only scratched the surface of PowerShell and its capabilities and just recently I picked up a copy of Bruce Payettes "Windows PowerShell in Action". So far, its a great book. I'll post a review when I'm done. But as I was reading I got into thinking about how I would like to Geocode addresses from the command line in certain instances. A custom PowerShell cmdlet was in fashion. 

 

The Get-GoogleGeocode CmdLet

At that point, the Get-GoogleGeocode cmdlet was born. I took my code from the C# Google Maps Geocoding class I wrote, added a new property "Address" (which is what I needed to store the address the user supplied) as a simple string and then wrapped it in a cmdlet. 

The result? An awesome cmdlet. 

The cmdlet will take your Google Maps API Key and a list of addresses and it will Geocode them for you. Very simple, yet very powerful. 

Lets take a look at what it can do: 

Examples

 

Note: My Google Maps API key has been hidden in the examples below ... SO YOU DONT STEAL IT! ;)

 

Script Explanation

Click the pictures for full resolution images.

 

 

Example 1:  Gets  the longitude and latitude for one single address and outputs it to the screen.

ps1

PS C:\Development\DF.PowerShell.Cmdlets\bin\Release> Get-GoogleGeocode -apiKey <YourAPIKeyGoesHere> -addresses "2203 E. Empire St. Bloomington, IL 61704"

Address Latitude Longitude
------- -------- ---------
2203 E. Empire St. Bloomington, IL 6... 40.488283 -88.945315

 

Example 2:  Gets the longitude and latitude for multiple addresses and outputs them to the screen. 

ps2

PS C:\Development\DF.PowerShell.Cmdlets\bin\Release> Get-GoogleGeocode -apiKey <YourAPIKeyGoesHere> -addresses "2203 E. Empire St. Bloomington, IL 61704", "8300 Norman Center Dr., Suite 950 Bloomington, MN 55437"

Address Latitude Longitude
------- -------- ---------
2203 E. Empire St. Bloomington, IL 6... 40.488283 -88.945315
8300 Norman Center Dr., Suite 950 Bl... 44.853079 -93.352194

 

Example 3:  (I think this is the REALLY cool one) Opens a file, reads each line and gets the longitude and latitude for each address in the file.

ps3

PS C:\Development\DF.PowerShell.Cmdlets\bin\Release> Get-Content c:\temp\MicrosoftOffices.txt | Foreach-Object {Get-Goog
leGeocode -apikey <YourAPIKeyGoesHere> -addresses $_ }

Address Latitude Longitude
------- -------- ---------
2203 E. Empire St. Bloomington, IL 6... 40.488283 -88.945315
77 W. Wacker Dr., Suite 2300 Chicago... 41.886499 -87.630526
3025 Highland Pkwy., Suite 300 Downe... 41.831445 -88.010731
500 E. 96th St., Suite 460 Indianapo... 39.928171 -86.150754
N19 W24133 Riverwood Dr., Suite 150 ... 43.056940 -88.229463
4601 Westtown Parkway, Suite 136 Wes... 41.610376 -93.711712
10801 Mastin Blvd., Suite 620 Overla... 38.932978 -94.702328
8300 Norman Center Dr., Suite 950 Bl... 44.853079 -93.352194
3 City Place Dr., Suite 1100 St. Lou... 38.670381 -90.433552
13815 FNB Parkway Omaha NE 68154 41.266103 -96.130733

 

Script HELP

If you ever forget about how to run this command, I have included the help files as well. 

Access help by typing: Get-Help Get-GoogleGeocode. This will give you very basic help. For detailed or full help type: Get-Help Get-GoogleGeocode -detailed or  Get-Help Get-GoogleGeocode -full

To use this script, execute the command Get-GoogleGeocode and supply a api key and a list of addresses separated by a comma. 

From help:

PS C:\Development\DF.PowerShell.Cmdlets\bin\Release> get-help get-googlegeocode
NAME
    Get-GoogleGeocode
SYNOPSIS
    This cmdlet will return the latitude and longitude of the addresses that are passed into the cmdlet.
SYNTAX
    Get-GoogleGeocode -ApiKey <String> -Addresses <String[]> [<CommonParameters>]
DETAILED DESCRIPTION
    This cmdlet will return the latitude and longitude of the addresses that are passed into the cmdlet. The apikey is
    required for this to work. Also, you may encounter proxy issues if you require a proxy for access to the internet.
    This cmdlet utilizes the System.Net.WebClient class to access the internet. This cmdlet will connect with the Googl
    e Maps API, ask for the geocoding information and then return it.
    You will need a Google Maps API Key for this. Sign up for one here: http://code.google.com/apis/maps/
    If the latitude and longitude are both ZEROS, this means the address could not be geocoded.
RELATED LINKS
REMARKS
    For more information, type: "get-help Get-GoogleGeocode -detailed".
    For technical information, type: "get-help Get-GoogleGeocode -full".

 

How to Install

Start powershell and navigate to the Release directory run the "install.ps1" script from the command line. It should look like this when you run it: 

install

 

How to uninstall?

Run the uninstall.ps1 script. Running that script should result in something that resembles this:  

uninstall

 

Downloads

C# Solution & Binaries: DF.PowerShell.zip (44.51 kb)

Note: Text File with Addresses from Example 3 is included in solution download.


Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.NET | PowerShell

Book Review: Be Prepared

by Donn Felker 18. September 2008 04:17

cover_dadnbaby Be Prepared - A Practical Handbook For New Dads

Being a new dad is sort of like anything else in life that you've never done before. Its confusing, its hard, its fun, its rewarding and well, its just plain hard to figure out. Babies are like computer viruses that always adapt. You have to figure out how to keep them within their sandbox before they get out and destroy everything. Before you can confine them to their sandbox, you have to figure out exactly how and what you need to do that. When it comes to babies, simple tasks can be quite daunting to a new dad. Some of these tasks are:

- How to Change  Diaper

- How to hold a baby

- How to decipher the different screams

- How to know how to "swaddle" them.

- What to look out for in your hormonal significant other after birth.

- etc, etc, etc.

 

The problem with most "daddy" books is that, well, um ... they SUCK. Real Bad. I'm not joking, try reading one. They make you want to puke or gouge your eyeballs with a turkey baster. Typical daddy books and other new baby books are instant cures for insomnia in my opinion. You get 5 pages into the book and they're talking about all the happiness in the world. Yeah. Right. Sure.

They are full of typical puppy dogs and ice cream nonsense.

I need a book that's for MEN. Plain and simple.

About two months ago while shopping for some baby gear at baby consignment shop I saw this half priced book store next to the baby shop. We decided to visit it and low and behold, I found the holy grail of daddy books.

"Be Prepared - A Practical Handbook For New Dads"

The image shown above is actually the cover image of the book.

 

You're probably wondering ...

Why this book is "SOOOOOO MUCH BETTTERRRRRR" than other daddy books?????

Well, lets be honest, it just is. But my opinion is just that - an opinion. Lets help you identify your own opinion and in this case an example is 10x better than reading boring lame-o text.

Upon cracking open this golden nugget of information goodness you're set up with a nice mental image of what the rest of this book will be like ...

Page-1 (source: beprepared.net):

samples_willnwont1

 

Page 2:

samples_willnwont2

 

 

One word for this.

AWESOME.

 

Finally a book that tells it like it is. A real-deal-holyfield approach to daddy books. I don't want a book that sugar coats everything for me. I want the book to explain exactly how life with a baby should be and will be. Be Prepared is that book. Hands down, this IS the book for new dads. If your significant other is asking you to read a daddy book, get this one. It will save your life, probably your babies life and it will help your relationship. :)

The Book provides tips and tricks all the way up to 1 year old. It covers it all.

- How to soothe a baby (and cool tricks I never thought of)

- How to change diapers

- How to bath the baby (at different stages too)

- How to deal with a hormonal woman

- How to read sports illustrated to the baby (get your sports and your kid bonding time at once!)

- How to take a baby camping

- How to handle crazy relatives who want to hold the baby, but you don't trust them

... and a TON more. This is only a grain of salt compared to the shaker of awesome-ness in this book. Literally, this small book is PACKED with goodness. It's so good I'm going to go buy a couple and give them to my friends who are going to be new dads.

The web site (www.beprepared.net) has all kinds of goodness too.

To view more sample pages check it out here: http://www.beprepared.net/sample.html 

 

If you're tired of reading nonsense baby books that your significant other has given you (not that they're full of bad content - just mind numbingly boring) then pick this book up.

 

Disclaimer: No, I did not get paid to write this. I honestly feel this is the best daddy book out there. Period.

Currently rated 1.0 by 1 people

  • Currently 1/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Misc | Book Review

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About the author

Donn Felker

Senior Consultant
MCTS
ScrumMaster
Agile Practitioner

About Me | Books I Recommend

Gotta Pay The Bills


Tag cloud

    Popular Posts

    RecentComments

    Comment RSS

    Calendar

    <<  September 2008  >>
    MoTuWeThFrSaSu
    25262728293031
    1234567
    891011121314
    15161718192021
    22232425262728
    293012345

    View posts in large calendar