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,896
  • GPS_2.jpg
    GPS_2.jpg
    61.6 KB · Views: 4,541
  • GPS_3.jpg
    GPS_3.jpg
    74.8 KB · Views: 48,822
  • GPS_4.jpg
    GPS_4.jpg
    46.7 KB · Views: 3,990
  • GPS_5.jpg
    GPS_5.jpg
    66.1 KB · Views: 4,070
  • GPS_6.jpg
    GPS_6.jpg
    33.9 KB · Views: 3,863
  • GPS_7.jpg
    GPS_7.jpg
    42.3 KB · Views: 4,101
  • GPS_8.jpg
    GPS_8.jpg
    33.1 KB · Views: 3,702
  • GPS_9.jpg
    GPS_9.jpg
    52.8 KB · Views: 3,990
  • GPSExampleV2_6.zip
    134.5 KB · Views: 2,254
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
Very nice Klaus!

An absolute treasure trove of info.

Love your work man!

----

Just some thoughts as how I would enhance this app.
May already be there.
Not asking anyone to do it.
But may do it meself if I get the urge.

----

Change input default location of Lng then Lat
to Lat then Lng

----

Add button to set default location to current GPS location.

----

Add button to set default location to current map centre.

----

Rename scale control to Scale Legend.

----

When exiting the setup don't reposition map to default location.

----

Add a setting to display zoom level as well. Like speed.

----

Add a setting to start at current GPS location and not default location.

----

Add a zoom level control.

----

Change zoom button to be transparent like icons.

----


Realy nice work, man.
Wow. Big WOW.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
I'm glad that you find the program useful :).

Your points:

Change input default location of Lng then Lat to Lat then Lng
No problem, it's just a move in the layout.

Add button to set default location to current GPS location.
Not difficult, add a button and a routine.

Add button to set default location to current map centre.
Not difficult, add a button and a routine.

Rename scale control to Scale Legend.
Controls is meant for the choice of the displayed map Scale, Type and Zoom controls.
The position is perhaps not the best one but saved some space, should have been on top of the three controls.
Can easily be changed in the layout.

When exiting the setup don't reposition map to default location.
Can be done in Activity_Resume of the Main module in changing the MapCenter values.

Add a setting to display zoom level as well. Like speed.
I didn't find the need for it. But could be added.

Add a setting to start at current GPS location and not default location.
When the GPS is activated the map is shown at the default location but as soon as the first location is found the map is centered on that location.
Could be changed in the btnGPS_Touch routine in the Main routine, but then you need to define what other position you want to show.

Add a zoom level control.
Already exists, it's display can be selected in the setup.

Change zoom button to be transparent like icons.
The zoom control is the internal control of Google Maps.
In my first version when I didn't know how to trap the zoom change in Google Maps I used a transparent 'home made' one. But then prefered to use the 'standard' one.

Feel free to change the program to your needs and wishes, thats the purpose of this example. If you have any problem please ask.

Best regards.
 

BarrySumpter

Active Member
Licensed User
Longtime User
Thanks for the reply and the suggestions klaus.
Love the easy and not diffucults.

I might be getting the scale control that doesn't show on my HD2 mixed up with the scale legend.

Zoom control is the + and - buttons.

I don't know the zoom levels.
So displaying them would be useful to me anyway.
Zoom levels are 1 to 20.
1 being farthest away.
20 being street level.

I'm not sure what first location is as different to other position.

Yes, was thinking the app should let google do absolutely everything then b4a extracts the values it needs.

Thank for permission to modify the example.

Any restrictions on distributions?

I've written before that I'm not trying to sell anything at all.
Been there. Done that. Major fail.

Just want to develop things for my family and friends.

I've got a google static maps kinda app that allows my bike riding buddies to find each other with kickoff points or coffee shops.

But that apps language isn't mature enough to work with extracting info from google live maps via javascript behind webviews.

And just found out the features I need are not going to be available anytime soon. So have decided to drop them again and focus solely on b4a.

So I'd like ot start with your example and enhance from there.
And use myself with my bike riding buddies n family n frieds.
Again, not interested in wasting time trying to sell anything.
Could I get your permission to do that?

Thanks again and all my best,
Barry G. Sumpter
 
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
Super-fast alternative to emulator -> x86 Android

I was just thinking the regular Android emulator was slow.

Especially on my computer with the Setup Panel having so many views (controls).

And found this excellent contribution from another billiant contributor.

Super-fast alternative to emulator -> x86 Android
http://www.b4x.com/forum/basic4andr...er-fast-alternative-emulator-x86-android.html

Very nice!

I was thinking this an appropriate place for mentioning this as developers who are editing the setup panel might appreciate it.
 
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
Need to update my list of enhancements:

Since I've been turning OFF the repositioning of the map to Default Lat n Lng
(usually happens after each button press)
I need to add a way to reposition to default lat n lng with another button.

Also, I was thinking I've seen other maps that hide all button on the map.
Then when the map is touched in any way to have them reappear for say 3 seconds.
Then fade out/dissapear again.

One map has a compass icon button in the top right corner to reposition.
But I think this one changes the orientation as well.

Another map has a pin icon button in the lower left to reposition.

I don't know which would be most appropriate.

Also, I really like Google Maps Sonar Bubble indicator for current position.
I wonder if anyone on b4a has developed this?

I've attached some compass icons.

Thank of course I'm wondering if Google Maps would do ALL this for us bysetting up ALL the right parameters via google.maps.api html.
As in getting Google Maps to do absolutely everything it can.
i.e. define scale buttons, scale legend, Bubble Sonar, etc

Then having b4a wrap it n pull out the right properties, etc.
 

Attachments

  • GPSCentreCurrLocIcons.zip
    13.1 KB · Views: 476
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
Hi Klaus,
I wanted to save an updated version of your GPSExample as GPSBGSExample and b4a.gpsbgsexample and get this error on compile:

B4X:
Compiling code.                         0.23
Compiling layouts code.                 0.02
Generating R file.                      0.00
Compiling generated Java code.          Error
javac 1.7.0_03
src\b4a\gpsexample\main.java:382: error: cannot find symbol
public satellites _satellites = null;
       ^
  symbol:   class satellites
  location: class main
1 error
----

The java error: "cannot find symbol" occurred when a Compiler does not recognize a class name.

The following are the reason for such an error -
1)When a programmer misspelled the name of the class.
2When a programmer does not Imported the class name.

-----

The original GPSExample download again and without changes compiles and executes without errors.

-----

I've downloaded and edited the original GPSExample yet again
Project | package name
original: B4A.GPSExample - where I thought caps were illegal
changed to: com.bgs.gpsexample - compiles but errors on phone
Absolutely the only change I've made.

-----

Any help would be greatly appreciated.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
Hi Barry,
I get the same result.
I also, copied the original project in a new folder and changed the package name, same result.
I tried different other things without success.

The only advice I could give is to copy the project but not change the package name, it works with B4A V1.9 even with a package name with upper case characters as long as we don't change them.

Best regards.
 

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?
 
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
Hi Klaus,

Does the original GPSSample track current location by changing maps?

I zoom to 17 and the map won't scroll to keep my current location visible.

Is there a way to track and keep my current location visible in the centre of the screen?
 

hansje

New Member
Licensed User
Longtime User
Thanks klaus,

I am trying to run jour app.
I am using a htc sensation and android version 4.0.3.
When i select the map-button the program is stopt.
(message "GPSExample stoped")
idem is i save a path.

any idear what i am doing wrong?

Greetings Hans
 

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?

Continue? Yes


B4X:
An error has occured in sub: 
main_activity_resume((java line:595) 
java.lang.RuntimeException: Object should first be initialized (ImageView)
Continue?
B4X:
 An error has occured in sub: 
 main_activity_resume((java line:2049) 
 java.lang.RuntimeException: Object should first be initialized (Panel)
 Continue?
1042

I've also tried to recreate from scratch but no go.

I'd like to recover my work without having to piecemeal it back together.
Is there a way to change the package name back to B4A.GPSExample somehow behind the scenes.

Like editing a jar file etc?

Anyone?

:sign0085:

Was able to retrive my work with help from NJDude.
Backed up my entire project.
Edited the problem .b4a file with a text editor.
And change to the following line:
from:
Package=b4a.gpsexample

back to:
Package=B4A.GPSExample

Working again now.
But can't have the original project installed and the updated project installed at the same time.
Bummer.
 
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
Wanted to post my updates to GPSExample:

My updates in Bold.
I'm glad that you find the program useful :).

Your points:

Change input default location of Lng then Lat to Lat then Lng
No problem, it's just a move in the layout.
DONE

Add button to set default location to current GPS location.
Not difficult, add a button and a routine.
DONE

Add button to set default location to current map centre.
Not difficult, add a button and a routine.
DONE

Rename scale control to Scale Legend.
Controls is meant for the choice of the displayed map Scale, Type and Zoom controls.
The position is perhaps not the best one but saved some space, should have been on top of the three controls.
Can easily be changed in the layout.
This was me getting confused about the Scale Legend and wanting a Scale Slider Control.
This Scale Control(Legend) is fine.
I want to add a Scale Slider Control.



When exiting the setup don't reposition map to default location.
Can be done in Activity_Resume of the Main module in changing the MapCenter values.
DONE

Add a setting to display zoom level as well. Like speed.
I didn't find the need for it. But could be added.
This was me not knowing the Zoom levels 0 to 19.
0 being max world view. 18 being map with address (lot) numbers.

Add a setting to start at current GPS location and not default location.
When the GPS is activated the map is shown at the default location but as soon as the first location is found the map is centered on that location.
Could be changed in the btnGPS_Touch routine in the Main routine, but then you need to define what other position you want to show.
More realtime testing needed here after my mods.

Add a zoom level control.
Already exists, it's display can be selected in the setup.
Me getting mixed up with names.

Add a zoom level (SLIDER) control.
May be able to implement via Google Maps API v3 commands.
And NOT a b4a control(view).


Change zoom button to be transparent like icons.
The zoom control is the internal control of Google Maps.
In my first version when I didn't know how to trap the zoom change in Google Maps I used a transparent 'home made' one. But then prefered to use the 'standard' one.
Acknowledged.


Feel free to change the program to your needs and wishes, thats the purpose of this example. If you have any problem please ask.

Best regards.

In the second image attached.
The Visual Designer shows the background panel between the forground panels.
I can mouse down on the background panel
then drag the background panel up and down to get to the offscreen forground panels.
I've added code to remove the gap between forground panels when executing.

hth
 

Attachments

  • screenshot-1336692838931.png
    screenshot-1336692838931.png
    85.9 KB · Views: 409
  • Virtual Designer Setup Layout.png
    Virtual Designer Setup Layout.png
    80.9 KB · Views: 413
Last edited:

jparkerri

Member
Licensed User
Longtime User
Has drawing Path on map been added by anyone?

Has the ability to leave a trail of the GPS positions on the map been added?
Also, how would I add a fixed KML file of a grid of lines to the Map? I'm trying to setup the GPS Example as a data logger while I steer a boat over a ladder style grid of transect lines. I need to see the lines (the KML above) and my trail so I know how well I'm following the lines and where I've already been.
Thanks. I love the program as it is.
 

klaus

Expert
Licensed User
Longtime User
Has the ability to leave a trail of the GPS positions on the map been added?
Yes, since the first version. You must check the function in the setup and when GPS is running the GPS path is shown on the map and can be saved as GPP file (proprietary file format) or as a KML file.

You can read GGP files, but only one at the same time. There is no function to read KML files.

But feel free to adapt the program to your needs.

Best regards.
 

hansje

New Member
Licensed User
Longtime User
Hi Hans,
Sorry, but I don't know what the problem is.
Can you run the program in Debug mode from the IDE and look at the Log message to see what caused the error.

Best regards.

Thanks Klaus,

I am new in the world of basic4android.
So i can not tell whats wrong here.
Maybe you can.
This is my log.

LogCat connected to: fone hans
--------- beginning of /dev/log/system


--------- beginning of /dev/log/main
** Activity (main) Create, isFirst = true **


** Activity (main) Resume **


** Activity (main) Pause, UserClosed = false **


** Activity (satellites) Create, isFirst = true **


** Activity (satellites) Resume **


** Activity (satellites) Pause, UserClosed = true **


** Activity (main) Resume **


** Activity (main) Pause, UserClosed = false **


** Activity (setup) Create, isFirst = true **


** Activity (setup) Resume **


** Activity (setup) Pause, UserClosed = true **


** Activity (main) Resume **


java.lang.RuntimeException: MotionEvent { action=ACTION_UP, id[0]=0, x[0]=231.1976, y[0]=922.0107, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=146898380, downTime=146898231, deviceId=4, source=0x1002 } recycled twice!


at android.view.MotionEvent.recycle(MotionEvent.java:1659)
at android.view.ViewRootImpl.finishMotionEvent(ViewRootImpl.java:2977)
at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2968)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2522)
at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:862)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2531)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4944)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)


at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)

I hope jou can make sense of this

Greetings Hans
 
Top