OSM Map On Garmin/Postcode Search On Garmin

From OpenStreetMap Wiki
Jump to: navigation, search

Compiled maps for Garmin don't seem to have postcode search function. This is a hack to enable a UK postcode search set on a Garmin Nuvi 255W, and I hope it would work similairly with others. Hope it helps you, as this was (until now), my main bugbear with OSM on a Garmin. With this hack, postcode coverage is better that that I have with the original Garmin maps (now 12 months out of date), and I didn't want to waste my money on an upgrade to fix this with no guarantee it would be much better with their current generation UK map.

Contents

Step One

Download CodePoint Open list of postcodes and grid references from OrdinanceSurvey http://data.gov.uk/dataset/os-code-point-open. Extract it wherever you like. Alternatively MySociety [1] make a version of CodePoint Open which has already been converted to WGS 84 lat/lon, which means step two might be unnecessary, and may save a bit of grief. SK53 23:11, 15 May 2011 (BST)

Step Two

Convert from eastings/northings to latitude/longitude. I used the Excel functions for doing this from Phil Brady http://pbrady.bangor.ac.uk/osgb.xls (because I had them readily available), and ended up writing the following code to convert directly to a reduced CSV file.

Step Three

If you haven't already done it in the previous step, use GPSBabel or similar software to convert your desired postcode coverage files to .GPI format

Step Five

Backup your POIs

Step Four

Copy the resulting file/s to your garmin device (under the directory X:\Garmin\POI (either on the onboard memory or on the memory card). If you put it on the memory card when it first reboots it will ask you if you want to install it permanently on the device. Initially I'd suggest not until you've checked it works properly for you, as it's a pain to have to do a mass delete and reinstall of all the POIs.

Step Five

Search for your Postcode in the installed POIs. On the Nuvi this is via Where To/Extras/Custom POIs/All Categories/Spell. Not sure how it will work on others tho.

Conversion Code

Sub createPostCodeFiles()
    Dim eastings As Long, northings As Long
'    Dim latitud As double, longitude As double
    Dim osReference As String
    inputDirectory = "D:\Downloads\Downloads\codepointopen postcodes_gb\Data\"
    outputDirectory = "D:\Downloads\Downloads\codepointopen postcodes_gb\output\"
    bmpName = outputDirectory & "postcode.bmp"

    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Const TristateFalse = 0
    

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set WshShell = CreateObject("WScript.Shell")
    
    Set oFolder = fso.GetFolder(inputDirectory)
    Set oFiles = oFolder.Files
    
        ' rename all the jpegs
    
    For Each Item In oFiles
        Debug.Print Item.Name
        inputName = inputDirectory & Item.Name
        outputName = outputDirectory & Item.Name
        gpiName = Replace(outputName, ".csv", ".gpi")
        
        Set curInputFile = fso.OpenTextFile(inputName, ForReading)
        Set curOutputFile = fso.OpenTextFile(outputName, ForWriting, True)
        
        ' Read from the file and display the results.
        Do While curInputFile.AtEndOfStream <> True
            TextLine = curInputFile.ReadLine
            ' Write to the file.
            postcode = Left(TextLine, InStr(TextLine, ",") - 1)
            postcode = Replace(postcode, " ", "")
            postcode = Replace(postcode, """", "")
            curLoc = instrOcc(TextLine, ",", 10)
            nextLoc = InStr(curLoc + 1, TextLine, ",")
            eastings = CLng(Mid(TextLine, curLoc + 1, nextLoc - curLoc - 1))
            curLoc = nextLoc
            nextLoc = InStr(curLoc + 1, TextLine, ",")
            northings = CLng(Mid(TextLine, curLoc + 1, nextLoc - curLoc - 1))
            osReference = MetresToOSref(eastings, northings)
            latitud = CDbl(latitude(84, osReference))
            longitud = CDbl(longitude(84, osReference))
            
            curOutputFile.WriteLine latitud & "," & longitud & "," & postcode
        Loop
        curOutputFile.Close
        curInputFile.Close
        
        ' your desired icon is the file listed in bmpName above
        shellStr = """C:\Program Files\GPSBabel\gpsbabel.exe"" -i csv -f """ & outputName & """ -o garmin_gpi,category=""Postcodes"",bitmap=""" & bmpName & """ -F """ & gpiName & """"
        Debug.Print shellStr
        ' If you have installed GPSBabel and want it to convert each file to gpi, then uncomment the following (delete the ' character from the beginning of the lines)
'        Set oExec = WshShell.Exec(shellStr)
'        Do While oExec.Status = 0
'            DoEvents
'        Loop
    Next
End Sub


Function instrOcc(stringToSearch, stringToFind, occurance)
    curLoc = 1
    For i = 1 To occurance
        curLoc = InStr(curLoc, stringToSearch, stringToFind) + 1
    Next
    curLoc = curLoc - 1
    instrOcc = curLoc
End Function
Personal tools
Namespaces
Variants
Actions
site
Toolbox