Share My Creation GPS Example

Do not use this program it is a very old one which was released before the GoogleMaps library was released.
Many things have changed since the release of this program and it does no more work as expected.
I have not updated it to satisfy the new requirements of Google which have become more and more restrictive.

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: 49,825
  • GPS_2.jpg
    GPS_2.jpg
    61.6 KB · Views: 4,523
  • GPS_3.jpg
    GPS_3.jpg
    74.8 KB · Views: 48,800
  • GPS_4.jpg
    GPS_4.jpg
    46.7 KB · Views: 3,974
  • GPS_5.jpg
    GPS_5.jpg
    66.1 KB · Views: 4,054
  • GPS_6.jpg
    GPS_6.jpg
    33.9 KB · Views: 3,849
  • GPS_7.jpg
    GPS_7.jpg
    42.3 KB · Views: 4,082
  • GPS_8.jpg
    GPS_8.jpg
    33.1 KB · Views: 3,686
  • GPS_9.jpg
    GPS_9.jpg
    52.8 KB · Views: 3,975
  • GPSExampleV2_6.zip
    134.5 KB · Views: 2,236
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
Added Map Explore mode to GPSExample v1.7c

When tracking current location with GPS on and Map on,
if the map is touched and moved,
GPS is Stopped and a Reposition to current location icon is displayed in the bottom left corner
and you can wonder around moving the map without tracking back etc.
Touch the Reposition to Current Location icon and your back to tracking current location.

.
 

Attachments

  • GPSExample v1.7c.zip
    135.6 KB · Views: 536
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
Please help debug - can't get gps to turn OFF

'bgs - 2012 06 22
' Added Auto GPS On - via btnGPS_Touch() in one second startup Timer
' Added Auto Map ON - via btnMap_Touch() in GPS1_LocationChanged


Solved GPS not stopping with the 1 second timer

.
 

Attachments

  • GPSExample v1.7d.zip
    136.5 KB · Views: 474
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
GPSExample v1.7e

'bgs - 2012 06 24
' ToolBox - Fade In and Fade Out using timers
' added ICOSFadeAnimation library
'
' Set Map_On to False on app exit
' - otherwise, if map_on at app exit, Map will auto display 0,0 As lat,lng on restart

.
 

Attachments

  • GPSExample v1.7e.zip
    138.1 KB · Views: 463

BarrySumpter

Active Member
Licensed User
Longtime User
GPSExample v1.7f

'bgs - 2012 06 25
' Timer - Stop GSP if Location hasn't changed in x mins
' to save on battery

.
 

Attachments

  • GPSExample v1.7e.zip
    138.1 KB · Views: 457

BarrySumpter

Active Member
Licensed User
Longtime User
'Enhancements by Barry G. Sumpter

'bgs - 2012 06 26
' Finally - found a way to force GPS off and Map off on exit

.
 

Attachments

  • GPSExample v1.7f.zip
    137.4 KB · Views: 499
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
Hi Klaus,

Is there a way to update the webview with a FishishedLoading event?

Each time the webview loads a new map there is a two to three second blank screen
with only the DirectionArrow.

I want to hide he Direction Arrow between screens.

Also, I'm thinking to reduce the blank between screens,
we could toggling visible between two webviews.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
Hi Barry,
You can add in the MapDisp routine the lines below just before If MapSetDraggable = False to add the 'tilesloaded' event.
B4X:
' adds tilesloaded event
HtmlCode = HtmlCode & ";google.maps.event.addListener(map, 'tilesloaded', function(){"
HtmlCode = HtmlCode & "B4A.CallSub('MapViewer_TilesLoaded', true); })"

If MapSetDraggable = False Then
And add following routine:
B4X:
Sub MapViewer_TilesLoaded
    ToastMessageShow("Tiles loaded", False)
    ' replace ToastMessageShow by your code
End Sub
Using two WebView views could be done.
On way would be to transmit to the MapDisp routine the WebView to update as a parameter and manage the two WebViews in the code. That way the MapDisp routine remains almost the same just one more parameter and change of the last but one line. The two WebViews could be an array.
Or to define a third webview variable containing the current active WebView.
For example: the two WebViews MapViewer1 and MapViewer2 and the third variable MapViewer. In that case the MapDisp routine remains the same as it uses MapViewer.LoadHtml. And set MapViewer = MapViewer1 or MapViewer = MapViewer2 to set the webview to update.

Best regards.
 

BarrySumpter

Active Member
Licensed User
Longtime User
Thanks for the verbose response Klaus.
Much appreciated.

I think I see where you're heading.

Where the rest of the script behind the original webview would remain static as needed to function as usual.

So instead of toggling the visibility between the two webviews,
I should simply have a webView2 for loading the page only.
With no further functionality behind webView2.

While the original webView displays the previuos page until
the webView2 is finished loading
then
MapViewer = MapViewer2

Which should cut down on the blank screen between page loads.

I'll see what trouble I can get into.

Many thanks.
 

BarrySumpter

Active Member
Licensed User
Longtime User
...
And set MapViewer = MapViewer1 or MapViewer = MapViewer2 to set the webview to update.
...

Can't seem to get this to work.
Is there another way to assign this that will work with the HTML?

Unless I can have both MapViewer and MapView2 point to the same events?
hmmmm.
 
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
'bgs - 2012 06 28
' Added TilesLoaded Listener function event to WebView
' to trap when WebView has finished loading
'
' Added MapView2 and toggle logic to fix / shorten blank screens on map change
'

A lot of trial and error.
The resulting script looks too easy.

Back to my original idea to toggle visible between MapViews.
Since I can have both mapViewers point to the same events.


Thanks for all the help Klaus!

----

update
'bgs - 2012 06 29
' Toggling mapViewers not working correctly. Fixed in various places


Still not perfect.
Direction arrow displaying in wrong place just before map change

Getting closer.

Any help from anyone would be grealy appreciated.

.
 

Attachments

  • GPSWxample v1.7h.zip
    138.4 KB · Views: 541
Last edited:

wm.chatman

Well-Known Member
Licensed User
Longtime User
Hello Klaus

This is of course a great example and I appreciate it very much that you have shared it here for other users also. The UI looks Great!
One request for your GPS Example. The App uses the internal GPS of the Phone!
And as I have found out, the Power of the Phone goes down pretty fast, using it. Is it at all possible to add a external Bluetooth Unit? This way a User has a choise between internal or external GPS. A external Bluetooth Unit would last a bit longer, when App is in use. Is this possible for you to add on?
 

klaus

Expert
Licensed User
Longtime User
I'm afraid that this would be more complicated here than in Basic4PPC.
Basic4PPC has a library manageing both the internal external GPS devices this is not the case in Basic4Android.
So you need to:
- manage the connection of the external GPS device
- fetch the GPS data
- extract the needed data.

I don't know if all external GPS devices send the same data and I don't have one.

Best regards.
 

BarrySumpter

Active Member
Licensed User
Longtime User
Hay Chatman,
I've added a 5 min timer to one of these versions to address the battery drain from the GPS.
Post #125.

Hope it helps.
 
Last edited:

wm.chatman

Well-Known Member
Licensed User
Longtime User
Hello Barry

OK got it. Could you maybe add somthing also to your App, to accsess the external Bluetooth??? This would really be great.:(
The external Bluetooth Unit I own works 8 plus hours, and is also a better option. Would you do this for me Barry???
Like I wrote Klaus: maybe to have a choice between the two. Either use internal, or use external. Would really be cool. :)
@ Klaus. Been reading about the Bluetooth deal, but I really dont know where to start, nor where to put all that code.
 
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
Its not my app at all.
I've just posted a few enhancements.
In comparison to the major contributors to b4a I'm a newbie hack.
All my work is based on their contributions and advice.
So all do respect and credit to b4a creators, contributors and developers.

I've attempted to solve the GPS drain issues with the 5 min timer.
So no extrenal battery nor GPS needed.

So my humble suggestion is to keep it simple as the creators and contributors of b4a encourage.

However, if you do decide to persue this subject
perhaps a bit more research on which libraries you might be able to use
then post a query in a new thead asking for advice based upon your reseach.

hth
 
Last edited:

wm.chatman

Well-Known Member
Licensed User
Longtime User
Hello BarrySumpter

I ought to have typed your enhancements, instead of your "App".
My misstake, it's a typing typo error. Did not mean to offend, if I did so.
And yes, all respect and credit to b4a creators, contributors and developers!

The "enhancements" are also great. :)
 

BarrySumpter

Active Member
Licensed User
Longtime User
Hi klaus,
Would you have an opinion on using the Location Manager Library as an alternative?
As I've mentioned before my GPS location drives me mad taking so long to discover when sitting at my PC and in various locations mentioned.

http://www.b4x.com/forum/additional.../13337-locationmanager-library.html#post75151

Could we implement in latest GPS Example?

Or perhaps point me in the right direction to get me started?
 
Last edited:

klaus

Expert
Licensed User
Longtime User
I could have a look at it but unfortunately not before a week, I will be absent till next saturday.
I have never used the Location Manager Library yet so I need to learn it first too before using it. And so difficult to give you any direction right now.
I put it on my to do list.

Best regards.
 
Top