[PAID] πŸ“ Location Service Extension

as usual you can download it from the download folder of the locationservice extension
Taifun
PS: this question better should have been a PM...

1 Like

Hi,
I have a simple application, it takes the Latitude, Longitude and Current Datetime from the Location Service and use it to call a PHP file by way of GET say, www.mywebsite.com/mylocation.php?latitude=abc&longitude=abc&datetime=abc. The PHP file then does its thing and insert the date passed through the URL into a MySQL database. The application does this per interval set by a Clock Sensor object block, when the Clock timer fires. All of his these functions naturally do not work when the screen/cellphone goes to sleep. Which is why I purchased this extension.

I just need the extension to do this in the background... no idea how though... can you help... @Taifun

Please follow the documentation

and set the BackgroundWeb property to true, the RequestMethod property to GET and the Url property to www.mywebsite.com/mylocation.php?latitude=LATITUDE&longitude=LONGITUDE&datetime=DATETIME
before starting the service

It also would be a good idea to check the example projects, for example the locationserviceSpreadsheet.aia

Taifun

No, the application sends a new Get request after a location changed event was triggered in the background, do NOT use a clock component, as this will not work in the background... see again the example projects about how to use the extension

Taifun

Is your extension able to give me Lat and Lng with the .Location Charged function with the application minimized?

No

From the documentation at App Inventor Extensions: Location Service | Pura Vida Apps

LocationChanged
Indicates that a new location has been detected.
Note: This event only will fire if the app is up and running.

And also from the documentation

Also a background web functionality is available which can be used to send the location data to a web service of your choice using a web request. This could be used for example to store the location data in a MySQL database or to send an email after a location change was detected while the app is not running.

The example projects show you how to use the background web functionality

  1. to send an email
  2. to send data to a MySQL database
  3. to send data to a Google spreadsheet

You can send data in the background to any web service of your choice. If it works with the web component, the it will work with the background web feature of the extension, too

For firebase, follow this approach

Taifun

Great extension. @Taifun is a magician! Actually, it is possible to get information from the TinyDB when app is in the background, no need to send data to the server. Below I will show my solution how to get the last position every 1 second in the background, show the notification once and stop background process after 10 seconds.

Firstly, we need to define namespase of TinyDB and TaifunLocationService tag, where coordinates will be saved. Pay your attention on the Namespace of TinyDB1. It must be "TaifunLocationService". After that we should start the Location Service.

Next - Create an background process. It may be created by any event, in this example - a Button, but in my app I'm using TaifunTools extension, which looks for app's activity and starts this Service when activity status become "stop".

Next - we are defining some variables for background process and periodic event, which will trigger the special procedure every 1 second.

Π‘Π½ΠΈΠΌΠΎΠΊ экрана ΠΎΡ‚ 2023-06-16 12-50-49

The following images will be parts of the "back_step_2" procedure, which is started periodically by the event we defined in the previous step. The number of blocks is large, and, so to prevent microscopic letters on images, I divide the images into parts, in which you will see the block from the previous part at the beginning and the block from the next part at the end. Well, let's continue.

You can use TinyDB with location data to store another data, which can be used in background. But, values of tags MUST be single - without any spaces, commas, "&" and "-" symbols, because they used for parsing. If you need to store data with "&" and "-" symbols, replace them to another in parsing blocks. Spaces and commas are using for parsing obligatory.
That's all.
Maybe my parsing procedure not ideal, but it works.
Here I'm attaching aia file with blocks above. This file without TaifunLocationService.aix.
This aia contains some free extensions:
NotificationsStyle extension
Itoo extension for background tasks
KIO4_Terminal extension

aia file with solution:
GetCoordsFromTinyDB.aia (114.6 KB)

BTW, @Taifun, how often extension add data to the TinyDB? Is it equal to
component_set_get

2 Likes

Nice work...
Can you please update the post with the images related to background usage with the Taifun extension here?

Yes... both time and distance interval properties are relevant, for details see the documentation App Inventor Extensions: Location Service | Pura Vida Apps

Thank you for your tests!
Taifun

There are a lot of blocks here... They will be too small on the picture. But, I will do it tomorrow. I'm not near the computer now.

1 Like

Thank you for your extension!

Done

2 Likes

TaifunLocationService non funziona in background perchè?

Hi guys! I've been reading for hours now but I can't find a solution.
I bought the Taifun extension to run the app in the background but I can't get it to work..
Can anyone actually make this work?
This is my code with saving on MYSQL
Thanks for whoever replies..

Salve ragazzi! Leggo ormai da ore ma non trovo soluzione.
Ho acquistato l'estensione di Taifun per far girare l'app in background ma non riesco a farlo funzionare..
Qualcuno riesce a farlo funzionare realmente?

Questo il mio codice con salvataggio su MYSQL

Grazie per chi risponderΓ ..
Luca

You are using the LocationChanged event, which only works while the app is up and running

Read the documentation and check the example projects. . Learn to use the background web functionality... there is a MySQL example included, which uses this method App Inventor Tutorials and Examples: MySQL | Pura Vida Apps

From the documentation chapter " Example blocks to send the location data to a MySQL database while the location service is running in the background":

query

This is the first time you are posting here in the community. Yes, an extension which uses services can be challenging, especially for new users. I also offer paid personal support by email. As I'm traveling currently this service will be available starting from July 15

Taifun

The problem on Android 5... My app works flawlessly on Android 12. Location Service works for an hour with no problems. However, the same app after installing on Android 5 does not work (Xiaomi)... Location Service starts fine, the service notification appears, but if I minimize the app to the background, the service notification instantly disappears. What can this be related to? I turned off power management for the app.

See here

Taifun

Go to the app's settings and turn on Autostart and disable battery optimization.

I did that. But with no success

It is most of the times, the autostart problem, try on another MIUI device if you have and check if it works. Note that device can still unconditionally kill the service to save battery. (Check for phone's battery optimization settings)

Interesting... Background process created with Itoo extension continue to work (I see the notification). But Location Service notification disappears immediately after moving the app to background. Do they have such big difference in the principle of working in the background?
I turned on the autostart and turned off battery saving. Does not work anyway.