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.
 

Attachments

  • GPS_1.jpg
    GPS_1.jpg
    62.1 KB · Views: 48,556
  • GPS_2.jpg
    GPS_2.jpg
    61.6 KB · Views: 4,351
  • GPS_3.jpg
    GPS_3.jpg
    74.8 KB · Views: 48,597
  • GPS_4.jpg
    GPS_4.jpg
    46.7 KB · Views: 3,815
  • GPS_5.jpg
    GPS_5.jpg
    66.1 KB · Views: 3,887
  • GPS_6.jpg
    GPS_6.jpg
    33.9 KB · Views: 3,687
  • GPS_7.jpg
    GPS_7.jpg
    42.3 KB · Views: 3,923
  • GPS_8.jpg
    GPS_8.jpg
    33.1 KB · Views: 3,532
  • GPS_9.jpg
    GPS_9.jpg
    52.8 KB · Views: 3,806
  • GPSExampleV2_6.zip
    134.5 KB · Views: 2,032
Last edited:

wm.chatman

Well-Known Member
Licensed User
Longtime User
Great job Klaus and works a Treat !! :sign0188:

Thank you so much.

Best regards,
William
 

gregwa

Member
Licensed User
Longtime User
Invalid Double - loc.Altitude

I tried searching the thread just in case someone had already posted this, but couldn't find anything.

In the sub GPS1_LocationChanged, I was getting an Invalid Double error when the code was trying to set:
B4X:
loc.Altitude = NumberFormat(Location1.Altitude, 1, 1)

It seems that being "Rocky Mountain High" is causing this to go into the bananas range. The value that is attempting to put into the double is "1,717.29". Of course this throws the error.

I "fixed" it by simply setting it this way:

B4X:
loc.Altitude = Location1.Altitude

Not sure of any ramifications yet, but I'll test it out.

Really nice program.

Gregwa
 

klaus

Expert
Licensed User
Longtime User
Hi Gregwa,

Thank you for reporting this error.

Anyway Setting a number with:
loc.Altitude = NumberFormat(Location1.Altitude, 1, 1)
is bad programming practice because NumberFormat returns a String and not a number.

Everywhere for numbers I replaced it by
loc.Altitude = Round2(Location1.Altitude, 1)
and for the others I replaced them with NumberFormat2 lines.

The source code in the first post has been updated.

Best regards.
 

gregwa

Member
Licensed User
Longtime User
Glad I was able to help.

I know there aren't many people living "at altitude" so I'm sure that's why it didn't get caught before. There's not much O2 here ;o)
 

klaus

Expert
Licensed User
Longtime User
I'm also living in a mountain country but I have never tested the program above an altitude of 1000m :).
I could have been at an altitude heigher than that in less than a quarter of an hour driving. But unfortunately I tested it only in the valley.

Best regards.
 

gregwa

Member
Licensed User
Longtime User
Well, as we say here, "Who would have thunk it?"
 

johnaaronrose

Active Member
Licensed User
Longtime User
Noobie queries

Yes, it is possible, but you need to write the whole map management and you need to calibrate the map. It could be done with a big bitmap and drawing the relevant portion on the screen, or having a big Panel and moving it. Or having calibrated tiles that could loaded and drawn on the screen. There could be a memory proplem depending on the bitmap size.
Is GPS allowed in the conditions you describe?

Best regards.

I'm considering amending your app to use a .jpg file (instead of .gpp) which is a scan of part of a British Ordnance Survey map (better resolution than Google Maps). I like the idea of having a big Panel containing the .jpg file contents & moving it. Could you direct me to the place where the existing .gpp test maps are displayed on the screen?
PS I downloaded some Google Map tiles on my phone (i.e. download for offline) but I can't find the place where Google Maps stores them. Which folder does it use? Alternatively, is there a way of making Google Maps (on a desktop using the Browser) download them?
 

klaus

Expert
Licensed User
Longtime User
The map is diplayed in the MapViewer WebView with the MapDisp routine.
All the scrolling is managed internally in the WebView.

If you want to use an image you must rewrite display part of the program using for example a ScrollView2D object.
You will also need to include the scaling of the map image.

I don't know where Google saves the map tiles, I have never worked with local map tiles.

You should also have a look at the OSMDroid - MapView for B4A tutorial.
The GPSExample was written before OSMDroid was available.

Best regards.
 
Last edited:

johnaaronrose

Active Member
Licensed User
Longtime User
Thanks

The map is diplayed in the MapViewer WebView with the MapDisp routine.
All the scrolling is managed internally in the WebView.

If want to use a an image you must rewrite display part of the program using for example a ScrollView2D object.
You will also need to include the scaling of the map image.

I don't know where Google saves the map tiles, I have never worked with local map tiles.

You should also have a look at the OSMDroid - MapView for B4A tutorial.
The GPSExample was written before OSMDroid was available.

Best regards.

Thanks, Klaus, for the info. I've considerably amended your app to load a .jpg map & I've removed coding concerning (e.g.) zoom from the setup (i.e. Setup.txt) file. This now gives a problem so I need to amend the file. But I can't find it now: I thought that it would be in the Files folder but it's not there. Could you post a copy of it?
 

klaus

Expert
Licensed User
Longtime User
I don't have a file for this.
The program looks if the exists, if yes it is loaded, if no default parameters are used and the file is created the first time Sub Activity_Pause is called.
You should delete the existing file and leave the program create a new one.

Best regards.
 

johnaaronrose

Active Member
Licensed User
Longtime User
Ref to B4A.GPSExample

I don't have a file for this.
The program looks if the exists, if yes it is loaded, if no default parameters are used and the file is created the first time Sub Activity_Pause is called.
You should delete the existing file and leave the program create a new one.

Best regards.

Thanks Klaus for the info. I've been trying to find the existing Setup.txt file without success: I've only just realised that Dir.Internal files do not show up using Astro / ES File Explorer as only the app that created them is allowed access to them: rather different to what I expect from Linux distros!

I've just changed the Package Name on your app that I've now butchered. I've also changed the Application Label (in Module Attributes of the .B4A file). I now get a problem in GPSModule (in the LoadPath Sub) on line "Main.GPSPath.Initialize". It has a Class Not Found Exception of "B4A.GPSExample.main$_gpslocation". Could this be due to the gpsmodule.java file containing the line "public static String _loadpath(anywheresoftware.b4a.BA _ba) throws Exception{
Debug.PushSubsStack("LoadPath (gpsmodule) ","gpsmodule",5,_ba,mostCurrent)"? I presume that the above ref to "B4A.GPSExample" originates from somewhere (either in the B4A file or one of the Project parameters) though I can't find it in any of the .java files. Could you tell me where it comes from?

PS I've attached the app's .zip file.
 

Attachments

  • OSMapGPS.zip
    132.9 KB · Views: 437
Last edited:

johnaaronrose

Active Member
Licensed User
Longtime User
How to examine .class & .dex files?

B4A.GPSExample was the previous package name.
I remember that there were problems in previous versions with package names having upper case characters.
You should set the package name back to B4A.GPSExample.

Best regards.

The previous package name of B4A.GPSExample must be somewhere in one of the files included in the attached OSMapGPS.zip file: B4A cannot remember it from a previous version of one of the files. I have looked at all of the files except for the .class & .dex files. However, I am not able to open them with a program so that I can look at them. What program can be used to look at these files?
 

Attachments

  • OSMapGPS.zip
    132.9 KB · Views: 391

johnaaronrose

Active Member
Licensed User
Longtime User
Fixed Class exception problem

I've fixed the Fixed Class exception problem: I think it was due to the phone ending up with 2 versions of the app. I'm now trying to figure out the use of the GPSPathFilename variable in conjunction with the test1.gpp file & its reading in the app. Is the test1.gpp file & the setting of the GPSPathFilename variable to it required in the app? In other words, does the test1.gpp file contain data for your location and should the variable be set to ""?
 

wm.chatman

Well-Known Member
Licensed User
Longtime User
Hello Klaus,

It has been a few years now since I have been here, and I want to say HELLO. I am back :)
Does you GPS Example have a Track back function ? I really need that, would like to find my Jeep again.
Is it possible for you to maybe integrate this function, or maybe at least set Waypoints, so I would be able to track back?

Regards to you,
William
 

klaus

Expert
Licensed User
Longtime User
Hi William,

Does you GPS Example have a Track back function ?
No, there is no track back function.
The GPS Example is a relatively 'old' project.
I have currently several projects in my pipeline and don't want to spend time on it.
Implementing a Track back function would need quite some time.
 

wm.chatman

Well-Known Member
Licensed User
Longtime User
old project or not it is very useable.
Your pipeline might be overloaded, but could you maybe think it over again, for me.
I really need a Waypoint function for Tracking back to Vehicle.
I would be willing to donate, for the time and headaches.
 
Top