Rolf van Gelder released some code samples on how to read the GPS and compass data from an Android phone.
The code is written for the Android – Processing environment.
Processing is an open source programming language and environment for people who want to create images, animations, and interactions. Initially developed to serve as a software sketchbook and to teach fundamentals of computer programming within a visual context, Processing also has evolved into a tool for generating finished professional work. Today, there are tens of thousands of students, artists, designers, researchers, and hobbyists who use Processing for learning, prototyping, and production.
Get the code samples here:
For Processing v2.x and v3.x, look at the Kentai Processing library for GPS and Compass functionality: