Share My Creation GPS Example

Here is a GPS Example program with following functions:
  • Connect the GPS
  • Get and display GPS information
  • Save a GPS path (program internal GPP format and Google Earth KML format)
  • Display the available satellites
  • Display Google maps
  • Display a GPS path on the map
  • Shows current GPS position on the map
Google map functions, user settable :
  • Display zoom control
  • Display scale control
  • Display a path
  • Display markers
  • Move a marker
  • Display coordinates (touch the screen)
  • Move the map / Display coordinates (touch the screen and move)
Some special features:
  • Table with first column always visible. Image GPS_3.
  • Touching a button changes it's color and shows a tooltip on top of the screen. Releasing it insides the button area executes the function and hides the tooltip. Releasing outsides the butoon area does not execute the function and hides the tooltip. This allows to check a button function without executing it. Image GPS_4
  • Touching some buttons displays 'subbuttons' to select other setup parameters more easily rather than doing it in the setup screen. Image GPS_5
Comments on the images:
  • GPS_1 Display of a GPS path with polyline and markers
  • GPS_2 Display of current GPS data with the position on the map
  • GPS_3 Display of GPS path data in a table
  • GPS_4 Main screen, display of a tooltip, just touched the PATH button before releasing it
  • GPS_5 Display of 'subbuttons' to select setup parameters
  • GPS_6 Display og Satellites data
  • GPS_7 Setup screen
  • GPS_8 Save screen with one button foe each file format
  • GPS_9 Shows InfoWindow
It is designed for smartphones and does work only in portrait mode.

The program needs following additional libraries:
- ByteConverter
- Dialogs
- RandomAccessFile
- WebViewExtras
- ScrollView2D

Thank's to warwound for the WebViewExtras library, that allowed adding events to the GoogleMaps WebView.

The programs functionalities are explained in the Basic4Android User's Guide and some code is also explained.
If there are some code parts you would like having explained in the Basic4Android User's Guide post the request in this thread.

Best regards.

EDIT: 2011.12.20 version 1.1
Updated the source code after the bug reports.

EDIT: 2011.12.21 version 1.2
Added the maptype_changed event, problem reported by dlfallen in post#21

EDIT: 2011.12.22 version 1.3
Changed the zoom calculation
Added MapTypeControlID choice
Added MapZoomControlStyle choice

EDIT: 2011.12.23 version 1.4
Amended the problems reported by dlfallen

EDIT: 2011.12.27 version 1.5
Added saving of a GPS path in Google Earth KML format.
Removed the short help file, the help is in the Beginner's Guide.

EDIT: 2011.12.28 version 1.51
Amended bug reported by timo in post #37

EDIT: 2012.02.06 version 1.55
Amended bug report by msains in post #56

EDIT: 2012.02.06 version 1.56
Amended bug report by alfcen in post #59

EDIT: 2012.02.08 version 1.60
Amended bug report by Andras in post #64

EDIT: 2012.06.02 version 1.70
Added most of Barry Sumpters' wishes
Amended input from Filippo (German forum)
Added an InfoWindow for the first marker, when clicking on the first Marker an InfoWindoe is displayed.

EDIT: 2012.06.12 version 1.80

Added a filter to remove close locations.
Improved some function and removed some bugs.

EDIT: 2012.10.09 version 2.00
Updated for tablets.
Works only in portrait on phones and both orientations on tablets.
Needs Basic4Android version 2.2 (uses AutoScale)

EDIT: 2013.03.06 version 2.1
Amended error reported in post #142.

EDIT: 2014.08.09 version 2.2
Added altitude above sea level post #175

EDIT: 2015.04.17 version 2.3
Amended error reported in post #179
Amended some minor bugs

EDIT 2018.02.15 version 2.6
Removed DoEvents
Replaced File.DirRootExternal by GetSafeDirDefaultExternal.


  • GPS_1.jpg
    62.1 KB · Views: 47,812
  • GPS_2.jpg
    61.6 KB · Views: 3,961
  • GPS_3.jpg
    74.8 KB · Views: 48,162
  • GPS_4.jpg
    46.7 KB · Views: 3,467
  • GPS_5.jpg
    66.1 KB · Views: 3,551
  • GPS_6.jpg
    33.9 KB · Views: 3,381
  • GPS_7.jpg
    42.3 KB · Views: 3,571
  • GPS_8.jpg
    33.1 KB · Views: 3,221
  • GPS_9.jpg
    52.8 KB · Views: 3,439
    134.5 KB · Views: 1,581
Last edited:


Active Member
Licensed User
Thanks for providing such a complete example showing much more than just how to access GPS.



Active Member
Licensed User
Hi Klaus,

What a beauty of an example and I do appreciate it so much that you share it here.

Very best regards,


Licensed User
Hi Klaus

Despite being YOU the Birthday boy, it's US who get the present!!! Thanks!!!!

I have one request:

Is it possible to draw a "Navigator" like path, from the actual device position to a marker?


Licensed User
Hi Paulo,
Is it possible to draw a "Navigator" like path, from the actual device position to a marker?
I'm afraid no, it could be possible to draw a straight line from the current point to a marker, but as I don't know any vertice of the roads I can't draw a Navigator path.

Best regards.


Licensed User
Am I right to think tha the Google Navigator uses the same engine as the Google Maps?

If so, would it be possible to replace the "google maps" portion of the app with the navigator one?...

Hope I am being clear enought...


Licensed User
Just found a very interesting page regarding the Directions API within the main MAPS API...

I believe that making a Library to simplify the most frequent/usefull functions of these API would be a HUGE task...
Anyone up to the challenge??


Licensed User
Hi Klaus
Thank you for this excellent example.But I didnt compaile B4A give error Sub not declare...


Active Member
Licensed User
Klaus, you may have noticed that in a recent update to my GPSlog program, I added mapping for the current location and for stored locations. I found an unexpected difference in behavior between the program running on my Motorola Droid 2, and my Acer Iconia a500 tablet. On the phone, the zoom control is displayed as expected, but on the tablet the zoom control is missing. I loaded your GPS example on both of my devices, enabled the zoom control on both, and tested it. I got the same result: no zoom control on the tablet. Any ideas why this is?

Another small problem with your example program is that I also enabled the map type control, and on the phone the Altitude label sits on top of the type control, making that control difficult to read.

Another strange behavior is this. On both devices (phone and tablet) with the zoom and map type controls enabled, the initial map view when switched to satellite view is at the default zoom level. When I click on the setup icon, change nothing, click back on the map icon the display is at maximum zoom.

The last two items should be easy to fix, but the missing zoom control on the table has be stumped at the moment.


Active Member
Licensed User
Absolutely beautiful example. Better than most commercial programs I have seen. Plus Source code included, so that there is an excellent reference for own creations. What more can you ask!

Thank you, Klaus.



Well-Known Member
Licensed User
Hallo Klaus,

Absolutely brilliant, well structured, and intuitive. Not just an example, moreover a fully fledged application. Sorry for splitting hairs, on the Settings screen, 'Dispaly' should read 'Display'.

Sincere congratulations on an unparalleled "example".


Licensed User
Thank you for your nice comments.

I didn't have a deap look yet, at the links you sent, but will do it.

Could you be more precise on what error you get and in what Sub.

Sorry, but I don't know either why on the tablett the zoom control is not displayed. I noticed that some other functions don't work either, for example marker title and marker_click event don't work.
Thank you for the bug report.

Thank you even for splitting the hairs, I appreciate this too, for me this must be part of improuvement. I am always impressed by your applications, very professional and very pleasent design. Unfortunately, astronomy is not my favorit domain.

The code in post#1 has been amended (version 1.1).

Best regards.


Licensed User
Dear Klaus

I download your zip files and copy B4A sample folder and open when I press RUN button give error I attached error message screenshot for you



Licensed User
I just downloaded the zip file from the forum and tried it, it works OK.

I download your zip files and copy B4A sample folder . . .
What do mean with this ?
You should copy the zip file in a folder, then unzip it in that folder, and run it from that folder, it should work.

Best regards.


Licensed User
I just downloaded the zip file from the forum and tried it, it works OK.

What do mean with this ?
You should copy the zip file in a folder, then unzip it in that folder, and run it from that folder, it should work.

Best regards.

Dear Klaus
:sign0013: sorry my english ( I am layz :) )
I am novice for android , yes of course unzip maybe I can not explain clearly

setep by step:
1-) downloaded your code 1.1 version
2-) unzip C:\Program Files\Anywhere Software\Basic4android\SourceCode\GPSExample\
3-) I see all code and modul files image files no problems but I didnt see apk files on object folder
4-) open Basic4android my pc and select GPSExample.b4a
5-) I see designer your activity
6-) I click RUN button ( blue arrow on toolbar)

and give error like this


I didnt understand why error ?
I want to thank you really have an educational application

Last edited:


Licensed User
thanks Erel :sign0098:
I solved with your proposal ( Turkish "I" and "i" problems I changed all ) and there are not some lib file my PC (webwievextra,dialog ) I found B4android wiki and dowload ....... now all ok

I tested
samsung galaxy tab
samsung ace

best regards


New Member
Licensed User
Klaus, thanks so much for posting this. It's a great primer for the use of various libraries.
I have the same problem as has been reported by someone else on my Xoom tablet - the zoom buttons are not showing. I'm curious about the resolution to this and will recheck this three regularly. Thanks again!