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,554
  • 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,886
  • 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,031
Last edited:

wm.chatman

Well-Known Member
Licensed User
Longtime User
Well I thought I would post this and maybe there would be some interest for these functions, as it would really make the GPS Example even greater.
If I had a chance to integrate such functions, I sure would not be asking for help on this, after guite some years not beiing online at this Domain.
These Enhancements would really kick off. Any helper are welcome and it would really put this litlle GPS Example to the Top.
It would be really great if we could set Waypoints/Tracks (individual) points that we can select.
I can select waypoint before I move away from vehicle waypoint 1, select the empire state buidng as waypoint 2,
waypoint 3, and so on. When I set these waypoints up in advance, they become a route.
The Track is where I actually walked. After I’ve walked all over who knows where, probably
deviating from my Route, I can find my track with the GPS unit and or save the track.
Or use the Trackback function to find my way back to the start. My Track will include some of my Waypoints, but
it will also include many other recorded points along the way. Using Trackback, I might see that I stopped
at the lake in Cetral Park at 2:57 PM, for example.

Btw Erel: This is a great and very clean site!
your tpl facelift is great, keep up the good work ;)
 
Last edited:

wm.chatman

Well-Known Member
Licensed User
Longtime User
Last edited:

arjian

Member
Licensed User
Longtime User
hi,is that possible to use custom marker instead of the original one,for example by changing in the code below :
B4X:
HtmlCode = HtmlCode & "chart?chst=d_map_pin_letter&chld=A|00FF00|000000'});"
 

klaus

Expert
Licensed User
Longtime User
What marker do you want to change ?
Directly with this:
B4X:
HtmlCode = HtmlCode & "chart?chst=d_map_pin_letter&chld=A|00FF00|000000'});"
No
You need to change the end of this line:
B4X:
HtmlCode = HtmlCode & "; var marker" & n & " = new google.maps.Marker({    position: new google.maps.LatLng(" & Pos.Latitude & "," & Pos.Longitude & "),map: map, title: 'Test" & i & "',clickable: " & MarkersClickable & ", draggable: " & MarkersDragable & ", icon: 'http://chart.apis.google.com/"
 

arjian

Member
Licensed User
Longtime User
You need to change the end of this line:
B4X:
HtmlCode = HtmlCode & "; var marker" & n & " = new google.maps.Marker({    position: new google.maps.LatLng(" & Pos.Latitude & "," & Pos.Longitude & "),map: map, title: 'Test" & i & "',clickable: " & MarkersClickable & ", draggable: " & MarkersDragable & ", icon: 'http://chart.apis.google.com/"

thanks,
i want to use a custom graphic file,something like this:

B4X:
HtmlCode = HtmlCode & "; var markerc = new google.maps.Marker({    position: new google.maps.LatLng(" & CenterLat & "," & CenterLng & "),map: map, title: '',clickable: false,icon: '" & File.Combine(File.DirAssets,"marker.png") & "' })"
but it doesn't work and i don't know how to fix it
 

klaus

Expert
Licensed User
Longtime User
What marker do you want to change ?
The center marker or the path markers ?
If it's the center marker you must change it in line
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' })"

You cannot use File.Combine(File.DirAssets,"marker.png")
you must use " 'file:///android_asset/marker.png' " instead

For the center marker try this:
HtmlCode = HtmlCode & "; var markerc = new google.maps.Marker({ position: new google.maps.LatLng(" & CenterLat & "," & CenterLng & "),map: map, title: '',clickable: false,icon: 'file:///android_asset/marker.png' })"
 

arjian

Member
Licensed User
Longtime User
hi
sorry to bother you again,i read a lot(e.g https://google-maps-utility-library...tags/markerwithlabel/1.0.1/docs/examples.html) but i couldn't find answer for following questions if you help me i would appreciate that
  • add a text to custom marker by changing code,something like this (of curse this code doesn't work):
B4X:
HtmlCode = HtmlCode & "; var markerc = new google.maps.Marker({    position: new google.maps.LatLng(" & CenterLat & "," & CenterLng & "),map: map, title: '',clickable: false,icon: 'file:///android_asset/marker.png&chld=A|00FF00|000000' })"
  • set the center of custom graphic marker to the Latitude and Longitude instead of bottom of marker
the second one is important to me and i know the first one is too difficult
thank you
 
Last edited:

klaus

Expert
Licensed User
Longtime User
1) Setting a value for title seems not working.
I made some trials but it doesn't work.
I looked at the documentation and found that title is shown on a PC only when the mouse hovers over the marker.
I'm afraid that this hovering function doesn't exist in Android and title is not displayed.


2) You can use this code, you need to adapt the values for size and achor.
B4X:
HtmlCode = HtmlCode & "var myIcon = { "
HtmlCode = HtmlCode & "url: 'file:///android_asset/marker.png', "
HtmlCode = HtmlCode & "size: new google.maps.Size(50, 50),"
HtmlCode = HtmlCode & "origin: new google.maps.Point(0,0), "
HtmlCode = HtmlCode & "anchor: new google.maps.Point(25,25), "
HtmlCode = HtmlCode & "};"
HtmlCode = HtmlCode & "var markerc = new google.maps.Marker({    "
HtmlCode = HtmlCode & "position: new google.maps.LatLng(" & CenterLat & "," & CenterLong & "),"
HtmlCode = HtmlCode & "map: map, title: '',clickable: false,"
HtmlCode = HtmlCode & "icon: myIcon "
HtmlCode = HtmlCode & "});"
 

Frank Tolsma

New Member
Licensed User
Longtime User
I am new to Basic4Android, but I like what I see so far...
For people who are trying this (nice) example project:

The 4 libraries listed in the first post are not the ones that are actually needed (anymore?).

The project also needs the ScrollView2D library. I could not find that one in the libraries list: http://www.b4x.com/android/wiki/index.php/Libraries, but I did find it here: http://www.b4x.com/android/forum/threads/lib-scrollview2d.19268/

It does not seem to need the Dialogs library, or at least: it compiles without it...
 

klaus

Expert
Licensed User
Longtime User
This code was written quite some time ago.
In between we have access to the GPS NMEA event where we can get the altitude above sea level in the GGA sentence.
I don't understand why the Google gurus don't return the altitude above sea level in the GPS_LocationChanged event.
Look at the first post, the program has been updated.
 

acortez

New Member
Hi Klaus. This is a very good GPS example I must say and I applaud you on this. Thank you.
But I'm having an error in this line of code on my Samsung Rush. I'd appreciate it very much if you can you shed a light on this.

Sub GPS1_NMEA (TimeStamp As Long, Sentence As String)
If Sentence.SubString2(0, 6) = "$GPGGA" Then
Dim vals() As String
vals = Regex.Split(",", Sentence)
GPSAltitudeSeaLevel = vals(9) <----------- throws an error
End If
End Sub

Error Description:
An error has occured in sub: java.lang.NumberFormatException:Invalid double:""

I don't know if this is phone related as I have not tested it yet with any other phone.
 

Roger Daley

Well-Known Member
Licensed User
Longtime User
Klaus

Thanks for posting this example/code. I had a vague idea for an APP to solve an old work problem [mental excercise] that would mean I had to come to grips with GPS, Google maps etc. and couldn't figure out where to start. Reverse engineering your example [stealing] is going to give me that knowledge and a whole lot more experience in B4A. Probably my 2015 project.
Great work as usual.

Regards Roger
 

Roger Daley

Well-Known Member
Licensed User
Longtime User
Klaus

A small bug, if there is no GPS signal and you press the GPS button you get an error. Error.jpg
The error comes from here:

B4X:
Sub GPS1_NMEA (TimeStamp As Long, Sentence As String)
    If Sentence.SubString2(0, 6) = "$GPGGA" Then
        Dim vals() As String
        vals = Regex.Split(",", Sentence)
                                                            'GPSAltitudeSeaLevel = 0
                                                            'If vals(9) <> "" Then
        GPSAltitudeSeaLevel = vals(9)    '<<<< Error Line
                                                            'End If
    End If
End Sub

I can eliminate the error with code shown as comments but as I am still trying figure out what is what you probably have a much better solution.

Regards Roger
 

klaus

Expert
Licensed User
Longtime User
Thank you for reporting this:
Try this code.
B4X:
Sub GPS1_NMEA (TimeStamp As Long, Sentence As String)
    If GPS1.GPSEnabled = True Then
        If Sentence.SubString2(0, 6) = "$GPGGA" Then
            Dim vals() As String
            vals = Regex.Split(",", Sentence)
            GPSAltitudeSeaLevel = vals(9)
        End If
    End If
End Sub
EDIT:
The code above doesn't work.
Use the code below:
B4X:
Sub GPS1_NMEA (TimeStamp As Long, Sentence As String)
    If Sentence.SubString2(0, 6) = "$GPGGA" Then
        Dim vals() As String
        vals = Regex.Split(",", Sentence)
        If IsNumber(vals(9)) Then
            GPSAltitudeSeaLevel = vals(9)
        End If
    End If
End Sub
 
Last edited:
Top