BASIC

Author Topic: Android GPS Location  (Read 2704 times)

Offline fivesprites

  • Mr. Polyvector
  • ***
  • Posts: 101
    • View Profile
    • FiveSprites
Android GPS Location
« on: 2013-Apr-27 »
Hi Chaps,

By request of a few of the #glbasic IRC regulars, here's an example of how to obtain GPS information on an Android device.  The information below refers to the V11 beta.  It should be simple enough to copy/paste code into a V10 release of GLB, but if you're finding difficulty then let me know and I'll post up some V10 sources.

First up, if you are using the V11.322 beta and have NOT modified the following files:

Code: GLBasic [Select]
       
        AndroidManifest.xml
        SDLActivity.java
        sdl_main.cpp
 

then you can use the files of the same name as attached and save them to:

Code: GLBasic [Select]
       
        C:\Program Files (x86)\GLBasic_v11\Compiler\platform\android\templateproj\AndroidManifest.xml
        C:\Program Files (x86)\GLBasic_v11\Compiler\platform\android\templateproj\src\com\glbasic\test\SDLActivity.java
        C:\Program Files (x86)\GLBasic_v11\Compiler\platform\android\bin\sdl_main.cpp
 

then, save the new file AndroidGPS.java to:

Code: GLBasic [Select]
        C:\Program Files (x86)\GLBasic_v11\Compiler\platform\android\templateproj\src\com\glbasic\test
 

Extract the GLB test app that and try it out and see the notes below.

However, if you have modified the above files then please compare and adjust accordingly :)

If GPS is disabled on your device then a dialog box will appear asking if you wish to jump to settings to enable it.

Important Note: The output may show 0 or some bizarre location initially.  You must wait for your device to lock onto a satellite, so please be patient before saying this doesn't work :D

Also, this is only a GPS implementation - it does not fall back to a Network Provider if GPS is unavailable. I will add this when I get time.

Assuming all of the above worked, then implementing GPS in your own project is very simple:

- Include the AndroidGPS.gbas file in your project

Use the functions as shown in the test project.

- When you don't need GPS anymore, call: stopGPS()

Apologies if this sounds a little complicated - it's late and I need sleep :)  If you need help then feel free to ask.

One last note: Thanks must go to spacefractal for the initial idea with the GLB/Android JavaCall:  http://www.glbasic.com/forum/index.php?topic=8621.0

//Andy

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2640
    • View Profile
Re: Android GPS Location
« Reply #1 on: 2013-Apr-27 »
Thanks Andy, it's a unique piece of code!  :good:
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3366
  • Integrated Brain
    • View Profile
Re: Android GPS Location
« Reply #2 on: 2013-Apr-27 »
Hey this it's very interesting... I think for mixing whit Arduino will be very cool... Thanks a lot!!!..