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:

dlfallen

Active Member
Licensed User
Longtime User
On the tablet zoom issue - In my GPSlog program I am able to zoom by using the usual 2-finger pinch method. This does not work in Klaus' GPS example because touching the screen causes a vertical and horizontal line to be drawn, along with the GPS coordinates of the point being touched. I like that feature a lot, but zooming is more important to me.

Would it be possible to add a button to toggle between your default coordinate mode and the zoom mode? Then you could have the best of both worlds.

I experimented with a custom zoom control in my program which worked well in map mode, but not in satellite mode. The problem is that the button resent the google maps request (at the new zoom level) and that request always defaults to the map view. Is there any way to change that default?

By the way Klaus, I agree whole heartedly with all of the folks giving you praise for your GPS example. I too think it is wonderful.
 

klaus

Expert
Licensed User
Longtime User
Thank you for the compliment.
Would it be possible to add a button to toggle between your default coordinate mode and the zoom mode?
It's already in there :).
Just touch the MAP button, move up to change to the draggable mode and release it, this works vice and versa. Can also be set in the setup 'Map draggable'. Explained in the short help file. The last setup is saved when you quit the program.

I will look at the map / satellit mode. When the map is redrawn by the program it is always in map mode.

I like your inputs, thank's for testing. That's the best and only way to improve programs.

Best regards.
 
Last edited:

Tom Christman

Active Member
Licensed User
Longtime User
Klaus, your contributions are greatly appreciated. It is truly a treat to view your code......concise and elegant. Thank You for this!
Tom
 

klaus

Expert
Licensed User
Longtime User
Version 1.2 updated in the first post.
Added the 'maptypeid_changed' event to memorize the selected map type reported by dlfallen in post #21.

@dlfallen
I set the ZoomControl type to LARGE.
Could you please test the new version to see if this solves the zoom control problem on the tablet.

@ Tom Christman, thank's :).

Best regards.
 

dlfallen

Active Member
Licensed User
Longtime User
Yes! The zoom control is now visible on my 10 in. tablet. I will have to try to get this to work in my program as well.

BTW, your map still exhibits this curious behavior (previously reported): When viewing the map, if you click on the Setup icon and then the Back button, the map displays at the fully zoomed in level rather than the level it was at before. Curious.

God Jul!
 

klaus

Expert
Licensed User
Longtime User
Version 1.3 in the first post.

@dlfallen,
Could you please test it once more with the zoom problem.
If you still get the problem could you look what happens in the CalcMapZoom routine in the Main module. I suspect that the problem was (is) there. I had never seen it.
Do you use it in landscape mode ? Normaly it shouldn't.

Best regards.
 

dlfallen

Active Member
Licensed User
Longtime User
V 1.3 does seem to solve the zoom problem, but two new problems appear:

(1) I keep getting the error message:

An error has occurred in sub.main_gps_locationchanged (java line: 1436)
Java.lang.RuntimeException: Object should first be initialized (Location).

(2) When viewing a map, if I click on the GPS icon I get the view showing latitude, latitude, and altitude but it quickly shifts back to the map view.

I am using the program in portrait mode only.
 

klaus

Expert
Licensed User
Longtime User
Once more thank's for testing. Version 1.4 in the first post

1) OK
2) It's a 'normal' behaviour. When you have a map displayed and you click on the GPS button, the program shows the map centered to the default center coordinates and the default zoon level. Then after getting the first fix, the map is centered to this fix and the fix is dispayed on the map (if 'Show GPS on map' is checked in the setup). The next fixes are shown on the map, when the fix gets near an edge of the screen the map is centered to the last fix. You can use the map controls in this mode, like the zoom.

Best regards.
 

latcc

Banned
What an excellent and first class App, Klaus! I am amazed. :)

I have a question. You use waypoints on a google earth map. Do you create these as GE points of interest files? I am trying to find code that creates a point of interest in google earth POI 'kml' format.
 

Smee

Well-Known Member
Licensed User
Longtime User
Klaus,

I too would like to add my thanks and praise. This really is an excellent well written program.

Congratulations and thank you very much for sharing. I am sure i will learn plenty from your code

Joe
 

timo

Active Member
Licensed User
Longtime User
Very well done, bravo Klaus.
Just one thing I noticed on distributing GPS apps: not all users are 'Androidians' and they may be in difficulties with this Intent:
'StartActivity(GPS1.LocationSettingsIntent)'; they often close the setting page by the 'home' button instead of the 'back' one. This make them be unable to propely reopen the app: if the app is still resident, they are forced to come back to the GPS setting page and remain confused. That's why I usually only show a msgbox pleasing them to set GPS 'on' and then to reopen the app. (I close with activity.finish after the msgbox).
This naturally depends on your consumer's target age.
 
Last edited:

AlpVir

Well-Known Member
Licensed User
Longtime User
The project is very interesting and offers interesting insights to each of us to improve your code.
However, it has, like all the examples I have so far been able to find a serious mistake in the calculation because of the height (as I understand it) does not take into account the geoid.
Basically I live to 545 m above sea level. My system hardware/software "external antenna --> Motorola Defy ---> TwoNav" correctly indicates 550 m or so.
Also use that, the internal antenna result (almost perfect) does not change.
The app. GPSExample indicates 595 m, very very different.
The difference (about 50 m) corresponds precisely to the result of the calculation done with the software "ClenGui.exe" (NIMA WGS 84 Calculator) or that derived from the computer on-line
http://earth-info.nga.mil/GandG/wgs84/gravitymod/egm96/intpt.html

It might be useful "EGM96Geoid.c" (easily available online) that should correct this error, but is written in C.
It is worth rewriting it in B4a or are there better solutions?
Or take a solemn corner?
 
Last edited:

latcc

Banned
Very well done, bravo Klaus.
Just one thing I noticed on distributing GPS apps: not all users are 'Androidians' and they may be in difficulties with this Intent:
'StartActivity(GPS1.LocationSettingsIntent)'; they often close the setting page by the 'home' button instead of the 'back' one. This make them be unable to propely reopen the app: if the app is still resident, they are forced to come back to the GPS setting page and remain confused. That's why I usually only show a msgbox pleasing them to set GPS 'on' and then to reopen the app. (I close with activity.finish after the msgbox).
This naturally depends on your consumer's target age.
If some users press HOME when they should be pressing BACK they deserve to remain confused. :)

Do you really believe it is necessary to cater for those who misuse their device in this way, Timo? If you add messages when a user mis-uses the buttons how are they ever going to learn to do things correctly?
 
Last edited:

klaus

Expert
Licensed User
Longtime User
@latcc,
You find an update of the program in the first post with saving of a GPS path in Google Earth KML format.

@AlpVir,
I had noticed that too, but haven't taken the time yet to look at it.
In the Basic4PPC GPS Driver library there is a SeeLevelAltitude property that gives the correct altitude. Unfortunately it seems that Android GPSs' don't have it (a bit disapointing).

@timo,
Depends on the 'consumers', some seem to be more open to adapt than others :).

Best gerards.
 

timo

Active Member
Licensed User
Longtime User
Klaus, this code let GPS1 be stopped if you push, by chance, on the left button (menu) because of this select case statement.
In this case i think it is better let the GPS1.Stop be managed by the Activity_pause or manage that pressure in the statement too.
What do you think about?
Ciao.

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 
   Dim Answ As Int
   Dim txt As String
   
   Activity.Title = ProgName & " : " & ProgVersion

   Select KeyCode
   Case KeyCodes.KEYCODE_BACK
      txt = "Do you really want to quit the program"
      Answ = Msgbox2(txt, "A T T E N T I O N", "Yes", "", "No", Null)
      If Answ = DialogResponse.NEGATIVE Then
         Return True
      End If
   End Select
   GPS1.Stop
   SaveSetup
   Return False   
End Sub
 
Last edited:

klaus

Expert
Licensed User
Longtime User
Hi timo,
Thank you for pointing this out.
I modified the code like this:
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 
    Dim Answ As Int
    Dim txt As String
    
    Activity.Title = ProgName & " : " & ProgVersion

    Select KeyCode
    Case KeyCodes.KEYCODE_BACK
        txt = "Do you really want to quit the program"
        Answ = Msgbox2(txt, "A T T E N T I O N", "Yes", "", "No", Null)
        If Answ = DialogResponse.NEGATIVE Then
            Return True
        Else
            GPS1.Stop
            SaveSetup
            Return False    
        End If
    End Select
End Sub
Best regards.
 
Last edited:

legion48

Member
Licensed User
Longtime User
Klaus, I can't get the example to run. I get this message:

Compiling code. Error
Error parsing program.
Error description: Unknown type: webviewextras
Are you missing a library reference?
Occurred on line: 138
Dim MapViewerExtra As WebViewExtras


The libraries that are referenced are:

Core
Dialogues
GPS
JSInterface
Phone
RandonAccessFile

Am I missing a reference?
 
Top