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,897
  • GPS_2.jpg
    GPS_2.jpg
    61.6 KB · Views: 4,542
  • GPS_3.jpg
    GPS_3.jpg
    74.8 KB · Views: 48,823
  • GPS_4.jpg
    GPS_4.jpg
    46.7 KB · Views: 3,991
  • GPS_5.jpg
    GPS_5.jpg
    66.1 KB · Views: 4,071
  • GPS_6.jpg
    GPS_6.jpg
    33.9 KB · Views: 3,864
  • GPS_7.jpg
    GPS_7.jpg
    42.3 KB · Views: 4,102
  • GPS_8.jpg
    GPS_8.jpg
    33.1 KB · Views: 3,703
  • GPS_9.jpg
    GPS_9.jpg
    52.8 KB · Views: 3,991
  • GPSExampleV2_6.zip
    134.5 KB · Views: 2,255
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
Back to the original GPS Example.

I'm finding that when I have GPS ON and Map ON as draggable,
my position IS tracking until my position navigates OFF the current map/screen.

When the app needs to load the next map,
it actually recenters on the default location.

I'd like the GPS example app to follow my location onto the next map/screen.

Any help would be greatly appreciated.
 
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
OK. Finally got the GPS Sample app to track my location continuously.

I think this was more trial and error than anything else.

Kinda flickers around a bit.
With blank screens between map loads over my amaysim data connection.

My testing:
If I'm at say zoom level 17 (which shows maybe 4 houses circle around my starting location),
when my location changes to where a new map is needed to display,
the zoom changes out to say 14 or maybe 11,
then loads another map
and will change maps correctly as needed.
But often at the zoom level I was on.

The giant arrow as a centre marker was distracting so I chaged it to a small pin. In after thought I would prefer the center marker to be the crosshair and the location marker to be a small green triangle showing heading.

Maybe later.

I'm not sure how much each map download is costing me on a phone network providers data connection like amaysim at $10 per gig.
Which always brings us back to offline storage like Google Maps 5.
So we don't have to pay for the same map download multiple times.

Here is my version of the GPS Sample app with tracking working for me.

If you find a better and/or smoother way please let us know.

Thumbnails show my setup parameters.
With Clickable and Draggable Markers both being OFF as well.

hth
 

Attachments

  • GPSSampleSetup1.png
    GPSSampleSetup1.png
    70.8 KB · Views: 447
  • GPSSampleSetup2.png
    GPSSampleSetup2.png
    70.3 KB · Views: 435
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
GPSExample v1.6 - BGS3

Track My Location working properly.
With my Setup updates.
I've added a Show Zoom Level cause Zoom level is still bugging me.

hth
 

BarrySumpter

Active Member
Licensed User
Longtime User
Anyone know how I can reference an app asset .png instead of a hyperlink to an icon in Google Maps API v3 html scripting?


B4X:
...
      'HtmlCode = HtmlCode & "; var markerc = new google.maps.Marker({    position: new google.maps.LatLng(" & CenterLat & "," & CenterLng & "),map: map, title: '',clickable: false,icon: 'http://www.google.com/mapfiles/arrow.png' })"
       HtmlCode = HtmlCode & "; var markerc = new google.maps.Marker({    position: new google.maps.LatLng(" & CenterLat & "," & CenterLng & "),map: map, title: '',clickable: false,icon: 'myAppAssetsPath/gpscenter.png' })"
...
something like
B4X:
 myAppAssetsPath = Path(File.DirInternal) & " \images"


Or perhaps I should pull the script for google maps to show center,
and add the centre myself as a transparent panel.
 
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
Thanks for the replies.


Waking from a good sleep all I can write is:
Doh! :BangHead:

I think I've even posted about how to do that myself.
Recently.

Burning the candle at both ends.

This code snippet works:

B4X:
Sub Button1_Click

    HtmlCode = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=windows-1252'><title>Test for android asset: gpscenter.png </title></head>"
  HtmlCode = HtmlCode & "<body>Test for android asset: gpscenter.png<p>        <img src='File:///android_asset/gpscenter.png' /></body></html>"

    MapViewer.LoadHtml(HtmlCode)

End Sub
And after 30 different unsuccessful permutations, this seems to work like I want it to:
http://www.b4x.com/forum/basic4android-updates-questions/12573-webview-google-map.html#post71389

B4X:
...
         Dim MyPNG As String
         MyPNG="file:///android_asset/gpscenter.png"
         
       HtmlCode = HtmlCode & "; var markerc = new google.maps.Marker({    position: new google.maps.LatLng(" & CenterLat & "," & CenterLng & "),map: map, title: '',clickable: false,icon:'" & MyPNG & "'})"
 ...
Or perhaps I should pull the script for google maps to show center,
and add the centre myself as a transparent panel.
Since the centre marker actually moves with the map,
I think this should be removed from the map and displayed as centre screen instead of centre map.
Or perhaps make the centre marker invisible if I move the map.
 
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
Another update.

Fixed maptouch up that would display a full screen cross hair at touch point and show the lat n lng for 1 second timer.
The lat n lng would show then disappear completely.

I've removed the visible = false and on 1 second timer tick replaced the lat n lng with LastLat n LastLng. i.e. back to currLat n currLng.

The zoom level was always getting set to 12 when CalcMapZoom.
Fixed.

I've left the map centre crosshair instead of the arrow.

The current location is still displayed as another different crosshair.
Change it back to the arrow if you want.

Will probably see if I can change the current location indicator to a direction arrow indicator.

Then display with DrawBitmapRotated to see if I can reflect direction.

Again, all due credit and respect to the original developer, klaus, as this is some really really nice work to begin with.

:sign0098: :sign0188:
 
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
Another update.

Have included a direction arrow with heading.

I did try a more accurate real time heading with phone sensors.
But found that when tracking the heading from the phone sensor didn't follow the street as well as the heading from the GPS sensor.
I left the phone sensors script in if you want to experiment.

I'm still finding a lag when on the road downloading maps.
The screen goes blank sometimes for 5 to 10 seconds.
I wonder if there is a technique to load the next map first,
the switch without the blank screen lag.

The direction arrow displays at different sized depending on the heading.
I understand this to be an issue with android.

I think Martin has written a new version of TouchImageView v2.
Where the automatic resize(?) of images has been turned off.
And want to test if I can use the TouchImageView as the direction arrow
instead of an ImageView which resized based upon heading.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
A new update, version 1.70, is available in the first post.
Includes 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 InfoWindow is displayed.

Best regards.
 

Dirk A

Member
Licensed User
Longtime User
Thank you for your very detailed example.
In my application I have to place 3 markers on the map. The coordinates of the markers are constantly changing . I would like to refresh their position every few seconds . The way that I would do it would be to update the MarkerPos list constantly and call MapDisp each time . But is it possible to redraw markers without redrawing the whole map?
If this is allready featured in your code ,could you be so kind to tell me where to look ?

thank you in advance
 

klaus

Expert
Licensed User
Longtime User
I think you need to draw the map each time.
But you could have a look at the possibiliy to use a MapView and Markers (in warwounds' OSMDroid library) to draw the map and perhaps there is a possibility to change the Marker positions without redrawing the map.
I haven't looked yet at MapView but will do in a near future and perhaps change it in the GPSExample.

Best regards.
 

exocet

Member
Licensed User
Longtime User
petit à petit l'oiseau fait son nid

: BangHead:: BangHead: problème de compilation je cherche librairie filedialog?....merci d'avance
 

klaus

Expert
Licensed User
Longtime User
Il semble que tu as des problèmes à trouver les librairies.
Dans le forum sous Additional libraries and official updates il y a un sous forum List of additional librairies dans lequel il y a la liste de toutes les librairies disponibles.
La librairie est la Dialogs librairie.

Meilleures salutations.
 

BarrySumpter

Active Member
Licensed User
Longtime User
Good find.

Offline has been available since v5.
i.e. saving visited maps onto android storage.
And not downloading them again.

But Full offline mapping looks to be as if we will be able to download full maps.
The article didn't mention FREE at all.
Nor open source.

Could be at a cost and propriatary.

Here's hoping.
Can't wait to find out whats on offer.
 
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
Thanks klaus,
Good to know its not just me and my environment.

If I change the package name to a 3 words like x.y.z
I don't get the compile error.

But on execution I get

B4X:
An error has occured in sub: 
gpsmobile_loadpath (java line:31) 
java.lang.ClassNotFoundException: B4A.GPSExample.main$_gpslocation
Continue?
which suggests to me that somehow the package name is NOT getting changed.
Or that somewhere the package name is hardcoded.


Maybe NJDude or Erel will post a suggestion?

------
Was testing GPSExample v1.7 and wanted to test my BGS updates but remembered this issue.
Was about to post again to see if any one had a solution yet and mention that this is the only important issue for me
I've had with b4a that was still outstanding.

But, I thought I'd have another go at fixing it.
And was successful.

OK, don't know why/how I got this working nor why/how it was an issue
but this is what I did.
Opened the GPSExample 1.6 project with b4a v1.92.
Changed the PackageName to com.bgs.gpsexample
Tools | Clean Project
Saved Project
closed b4a
opened the project again with b4a v1.92

Commented OUT the following lines:

B4X:
...

Sub Activity_Create(FirstTime As Boolean)


'        If File.Exists(GPSDir, GPSPathFilename) = True Then
'            GPSModule.LoadPath
'        End If

...
And tested successfully.

I can now have GPSExample v1.6 and GPSExample v1.7 and any other variations I've updated installed on the same phone.

Before, since I couldn't change the Package names, all the versions were getting installed on top of the previous one.

But not anymore.

Don't know why this was as issue in the fist place but so relieved I can test this way now.

I do know that the file Test1.GPP and Test2.GPP both have B4A.GPSExample embeded/hardcoded in the top of their binarys.

Might be an indication of where the issue lies? Or not. LOL

hth
 
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
Added direction tracking arrow to GPSExample v1.7b

B4X:
    'Enhancements by Barry G. Sumpter
    'bgs - 2012 06 21
    'Added direction tracking arrow
    'Changed package name


Other enhancments I'd like to implement:

connect to GPS at startup
msgbox "Waiting for GPS Location"

show button contol panel at first map display then fade out
fade back in on map touch
etc
 

Attachments

  • GPSExample v1.7b.zip
    135.2 KB · Views: 564
Top