HOW TO: use LocationService extension Version 1 and Version 3 with a GoogleSpreadsheet to record real time locations while the app is in the background

Yes, he does.

This Block will allow you to use a user name by adding a new item to the list. The Dummy Name is UserName. You can change the name for each user of your app using Blocks to Samuel, Steve etc. if you set a variable in a modified version of this code to allow the user to use a TextBlock to set the appropriate UserName.

When I use this script in your Spreadsheet,

//This script is bound to the spreadsheet. It therefore uses getActive() to get the

//spreadsheet it is bound to, and getSheets()[0] to get the first sheet in the spreadsheet

var ss = SpreadsheetApp.getActive();
var sh = ss.getSheets()[0];

//POST function appends all data sent as parameters to the next row on the sheet, in the order sent

function doPost(e) {

var data = JSON.parse(e.postData.contents);

sh.appendRow(data);

return ContentService.createTextOutput(data);

}

//GET function returns sheet values as a stringified JSON

//Using getDisplayValues() returns all values as strings

//This is not an issue in AI2 as number=string=number

//Use getValues() if you want original value formats

function doGet(e) {

var data = JSON.stringify(sh.getDataRange().getDisplayValues());

return ContentService.createTextOutput(data);

}

you should see something like:

username2

in your spreadsheet.

Hope this helps. Sorry, I cannot debug YOUR code; Taifun might help. You are doing a lot of things that are not possible with what code is used in the tutorial.

Also note, the code will not work on your device if it is Android 10+unless you set the Location permission manually using the system Settings for your device probably for Android 10+ . The tutorial mentioned it works on Android 8.1 and it does without asking for permissions.

@SteveJG is still using version 1 of the extension...
Of course there still is a POST method available also in version 2, it only looks a bit different...and you are using it correctly...

You are on a good way already with your blocks.. why not adjusting your blocks as I already suggested earlier?

Taifun

ok so I'm officially at my wits end, I've tried looking at the example aia file which isn't helpful, I've played around with the block that many times I've lost count. Could some look at my blocks and tell me how to enable it to post to a google sheet in the background. Nothing i do seems to work in the slightest.

Hi Samuel.

  • @Samuel_Dutton did you test the Post as suggested by Taifun? I Loaded extension version 2 and my spreadsheet test works. Does your testing of Post work? This code posts the words LATITUDE and LONGITUDE to columns 1 and 2 or the spreadsheet; however it will not post the actual latitude and longitude.
    postToSpreadsheet . This confirms that the POST works when used outside of the Service code.

  • The code example I show in the tutorial works with extension version 1. I originally tested it with Android 8.1; later I tested it with Android 11 too . Version 1 worked fine and it works with Android 12 also.

  • I cannot get extension version 2 to work with my Android 12 cell. What is frustrating is that I can get the app working using version 1. A suggestion is for you to ask @Taifun to kindly provide you with a copy of Version 1. Use my example code with version 1. After you get the simple app working, save a copy of the Project then add your ring fence code.

  • at the present time, I too can not figure out how to use Version 2 of the extension (what you have) with a Google Sheets script. When I compile, I get errors from Google's Play Protect saying there is a bug in the app. The problem seems related to his substitute Location Sensor or something else or issues in my coding.

  • Perhaps Taifun could show both of us some simple Version code to post coordinates to a google sheet. I have given up using Version 2 since Version 1 works for my purposes. :cry:

That's the same problem I'm getting. I cannot get it to post unfortunately. I'll ask for version 1 from Taifun if he would kindly do so.

Taifun as kindly given me version1, if its not to much to ask Steve could you send me a copy of your aia file and script as mine won't post? I've double checked the script, copied yours ect I know it's frustrating but would be a big help. I'm starting to think it's android version 12 that's the issue.

Great :slight_smile:

I don't think so. My app compiled with nb189 and Companion 2.64 works fine. My Samsung A13 updated to Android 12 on August 24. The app I compiled prior to MIT's nb190 and Companion 2.64 works FINE on my A13; using the identical code after the 24th no longer works properly. It compiles but it does not run in the background.

I suspect the issue is it does not have a Background permission.

@taifun, are users of Version 2 reporting any issues running on apps compiled using nb190?

A guess is nb190 requires either a Background permission or a simultaneous Coarse and Fine Location declaration (see GPS with Android 12 - #42 by ewpatton ) . I really don't know.

@Samuel_Dutton If you add a Button and the following to the app, does it post on your spreadsheet?
postLocation
When I add the code it posts with either LSVersion1 or 2 and provides a test checking your script and spreadsheet. However the service never starts in either my Version 1 or 2 app using nb190.

Sorry I cannot provide any additional help. I am going to see if I can find a copy of Companion 2.64 and see if rolling back to it will allow the Version 1 extension to work properly. At the moment, recompiling my Version 1 app does not work but prior apk's work fine.

I will investigate what is going on and let you know soon... most probably something has to be upgraded after we now are using SDK31...
Taifun

this is the error after the SDK31 release
Unbenannt
I'm working on a fix...
EDIT: this is the same issue which has been reported here Runtime Error: Targeting S+ (version 31 and above) requires that one flag of FLAG_IMMUTABLE be specified[...] - #8 by ewpatton

Taifun

2 Likes

how to get version 3?

This is a paid extension. You will have to buy it from the extension author.

I have purchased version 1, upgrade to version 3 must be paid again?

Nope, I think Taifun has shared a folder with you that contains all purchased extensions (or maybe it's an email). I think you should contact the extension developer, not me.

OK, thank You.

Thank You, You helped remind me about sharing folders from Taifun. I have found extension version 3 in shared folder.

1 Like

Please help how to add the script You mean and how the script?

image

it is recommended to create with the name spreadsheet, but you use the name LocationService
What is the difference?

here are the instructions

I tried it and it worked

  1. use the advice provided in TIm's tutorial: [quote="SteveJG, post:1, topic:33313"]
    Use Tim's advice showing how to use PUT with Google Sheets step by step to post the coordinates to the Google Sheet .
    [/quote]

You can name the spreadsheet anything you want. I named the spreadsheet I used LocationService so the spreadsheet has a name easy for me to remember. You do not have to name the spreadsheet. :slight_smile:

Thank you very much

6 posts were merged into an existing topic: [PAID] :round_pushpin: Location Service Extension

3 posts were merged into an existing topic: [PAID] :round_pushpin: Location Service Extension