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:

alfcen

Well-Known Member
Licensed User
Longtime User
Hallo Klaus,

Without the latest IDE 1.8, I would not have found the undeclared variables, in that the credit goes to Anywhere Software's B4A. The latest B4A IDE is awesome, indeed.

I do appreciate very much that you took everything in best faith.

Are you still developing such hi-grade applications with the emulator only?
This is amazing!

Cordialement
Robert
 

Andras

Active Member
Licensed User
Longtime User
I seem to be having a problem with the program; after installing it on my phone to see how it actually 'works' in the real world, I find that the map never updates, regardless of the latitude and longitude co-ordinates given, and regardless of where I actually am.

It picks up the satellites wonderfully well, but seems to do nothing with that data. Also on closing the program the GPS function remains active on the phone, whereas I'd expect it to close.

I'm clearly missing something here, but what?

John
 

klaus

Expert
Licensed User
Longtime User
Are you still developing such hi-grade applications with the emulator only?
No, I have a Nexus One device. But I'm still using the emulator a lot for the layouts.
I've got a new computer and the emulator is much faster than before.

I find that the map never updates, regardless of the latitude and longitude co-ordinates given, and regardless of where I actually am.
Have you checked in the Setup 'GPS Show GPS on map' ? If not the map will not be updated.
You should also check: 'Save GPS path' and 'Draw GPS path'.
You can also set default coordinates for the map in the setup. The map will be centered at that location by default. You can also set the default zoom level.
Also on closing the program the GPS function remains active on the phone, whereas I'd expect it to close.
I checked in the code that GPS1.Stop is really called: OK.
I then checked on my decive and the GPS is stopped after leaving the program. Sometimes it's not immediate.

Best regards.
 

Andras

Active Member
Licensed User
Longtime User
Thanks Klaus, that's very helpful and I've now got it to recognise my location at least; but whatever lat. and long. I type in as the default co-ordinates are ignored. Shouldn't the program jump to those automatically when it starts?
 

klaus

Expert
Licensed User
Longtime User
Hi Andras,
I apologize, you were rigth. There was a problem with the map display not centered on the default coordinates.
The zip file in the first post is updated, version 1.60.

Did you know that the program is explained in the Beginner's Guide ?

Best regards.
 
Last edited:

Andras

Active Member
Licensed User
Longtime User
Thanks, Klaus - I'll try it out again! Most grateful for the help!

Yes, I know about the explanation; I'm going to try working through the program to see exactly how it works. I must say that the more I use B4A, the more I like it!

John
 

Andras

Active Member
Licensed User
Longtime User
Actually, Klaus, I'm still getting the same result with the new version; Lat. 51.48376, Long. -3.18333 should give me Cardiff Castle, chosen because it should be easily recognisable; it's actually giving me the Autoroute Suisse and its environs, though I haven't bothered to work out exactly which town I'm in.

Your home town, perhaps?

John
 

latcc

Banned
Klaus

I would like to use this example to create an air navigation map for cross-country paragliding. The only problem is that in the UK we are not allowed by law to have a phone device working in the air. (Due to the phone mast triangulation system being overloaded when the phone picks up a wide range of masts at the same time.)

So using google maps downloaded by phone is not legal or possible (phones don't work properly when you are flying above 500 feet.

Is there any way, with your superb example, that I can use a moving map graphic that is already present on the device, rather than having to download it via the phone connection?
 

klaus

Expert
Licensed User
Longtime User
Is there any way, with your superb example, that I can use a moving map graphic that is already present on the device, rather than having to download it via the phone connection?
Yes, it is possible, but you need to write the whole map management and you need to calibrate the map. It could be done with a big bitmap and drawing the relevant portion on the screen, or having a big Panel and moving it. Or having calibrated tiles that could loaded and drawn on the screen. There could be a memory proplem depending on the bitmap size.
Is GPS allowed in the conditions you describe?

Best regards.
 

latcc

Banned
Yes, it is possible, but you need to write the whole map management and you need to calibrate the map. It could be done with a big bitmap and drawing the relevant portion on the screen, or having a big Panel and moving it. Or having calibrated tiles that could loaded and drawn on the screen. There could be a memory proplem depending on the bitmap size.
Is GPS allowed in the conditions you describe?

Best regards.
Hi Klaus

Yes, GPS is allowed in flight. I have been flying with GPS apps for a long time. I was wondering if I could download the google tiles I might need in any flight and somehow store them and retrieve them as needed from memory, rather than downloading them from the internet. That would be the simplest way to change your code. Have you any suggestions how I might read these google map tiles from the phone rather than the internet?
 

hdtvirl

Active Member
Licensed User
Longtime User
Klaus, I would just like to add my "Thanks" also to you for sharing this example with us, this is the way all Android Apps should be written and I for one will use this as my benchmark for any apps I write from here on in, the whole package is just perfect. I was only looking for an example of using scrollviews in a more user friendly way and now I have a Best Practices example for B4A not just for scrollviews.

My app is very boring in comparison as all it does is present figures in a scroll view and Barcharts.

Once again Thank you.


Regards

hdtvirl.
 

TomDuncan

Active Member
Licensed User
Longtime User
I am having the same problem with the map not being positioned for me in Australia. I have gps selected gps, maps and in setup have markers and polyline unchecked.
I get a europe map with a down facing green arrow.
It is a bit strange but it has worked for me once. Now refuses to on both an HTC Desire and Motorola Xoom.
Tom
 

JMoore

New Member
Licensed User
Longtime User
Hi
I have been trying to get the GPS example started but get the following errors

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
 

klaus

Expert
Licensed User
Longtime User
As the error message explains it, you are missing the WebViewExtras library.
You can download it here.
You must copy the jar and xml files to your additional libraries folder.
Then you should see the library in the Libs Tab in the lower right corner of the IDE and check it.
For more information on additional libraries you could read chapters 4.3.4, 18.1 and 18.2 in the Beginner's Guide.

Best regards,
 
Top