Sunday, July 20, 2008

NMEA GPS & 22 lines of PowerShell

Inspired by the python article "GPS + Google Maps Mash-up in 42 lines of code", I decided to create something similar in PowerShell:

function Nmea2dec {
    Param ([double]$degrees, $o)
    $deg = [math]::floor($degrees/100.0)
    $frac = (($degrees/100.0) - $deg)/0.6
    $ret = $deg + $frac
    if ($o -eq "S" -or $o -eq "W") {$ret = $ret * (-1)}
    return $ret

$port = new-Object System.IO.Ports.SerialPort COM1,4800,None,8,one
$line = ""
while (-not ($line -match ".GPRMC.*")) {
    $line = $port.readline()
$splitline = $line.split(",")
$latitude = Nmea2dec $splitline[3] $splitline[4]
$longtitude = Nmea2dec $splitline[5] $splitline[6]
$url = "$latitude,$longtitude&q=$latitude,$longtitude&z=16&t=h"
$ie = New-Object -ComObject InternetExplorer.Application

If you want to play around with the script above, you'll of course need a serial GPS reciever, or you could just use the following line of data:

I think I'll continue to play around with GPS data and Google Maps for a while - look out for PS scripts!

No comments: