Some help

1840 views
Skip to first unread message

Ispas Laurentiu

unread,
Jun 3, 2019, 1:06:17 PM6/3/19
to MIT App Inventor Forum
This is my code blocks for my app who make a picture and upload it on Google Drive. What do i want to do next is to use LocationSensor and to send the coordonate with the photo on google drive . So my question is how can i do that ? How can i use the LocationSensor component to do that.. and how can upload it with the photo in google drive if they are just some coordonates ?
123512.png

Andrés Martín

unread,
Jun 5, 2019, 1:14:34 PM6/5/19
to MIT App Inventor Forum
Yo soy totalmente novato, vale y nunca he hecho lo que cuentas. Pero te doy algunas ideas que se me ocurren.

1. Has hecho una foto y la guardas en Google Drive
2. Despues captura la coordenadas de esa foto, creo entender.

Tu pregunta es como guardas estas coordenada. Yo supongo que la foto tiene un nombre, pues junto al nombre le añades a esa cadena las coordenadas de esta forma: Nombre_Coordenadas.jpg 

¿Que te parece?

Hay gente que a la foto en el principio o en el final de forma binaria le añade información pero eso es mas complicado.
Message has been deleted

Ispas Laurentiu

unread,
Jun 6, 2019, 7:48:17 AM6/6/19
to MIT App Inventor Forum
Thx for reply. I appreciate if you will text in english:) But if i understood right, you Tell me to name the photo with the coordonate.. But i need to send them separetly. Because after that i need to extract coordonate for another program. So what i want it s to Send coordonate same time with the photo but separetly.

SteveJG

unread,
Jun 6, 2019, 9:47:13 AM6/6/19
to MIT App Inventor Forum
What you want to do is complex Ispas.   Here is how you might do it:

Take you picture.
Transfer your picture to a Canvas  (set the Canvas background image to the picture image)
Use the Canvas.DrawText block to add the location coordinates from the LocationSensor to the Canvas image
Save the Canvas to a png or jpg ....    call Canvas.SaveAs   block
Send the 'saved' canvas to Google Drive.

You however said "But i need to send them separetly. Because after that i need to extract coordonate for another program. So what i want it s to Send coordonate same time with the photo but separetly..

You can do that too.   Send the image to google drive, then send the coordinates from the LocationSensor as a text file to Google Drive  using the same Name as you labeled your image.  For example:

myPicture.png       myPicture.txt      where myPicture.txt contains the coordinates.

Is that what you want to do?   You have to send the Picture and the text to Google Drive.

What have you tried Ispas?   Post an image here in the Forum of your Blocks and someone will provide specific suggestions.

Regards,
Steve

Ispas Laurentiu

unread,
Jun 6, 2019, 10:04:12 AM6/6/19
to MIT App Inventor Forum
I already can send photo. My problem is to send coordonates with locationsensor. So, for do what i want ,to send the coordonates, i need to make that you Said with canvas blocks? And for that text File with coordonates to send on google drive, i need to save the coordonates first into a File then send them ? Or if i make with canvas i cansend them from there ?

SteveJG

unread,
Jun 6, 2019, 10:30:42 AM6/6/19
to MIT App Inventor Forum
Send the coordinates to GoogleDRive as a file or you can add  text to a Google Spread sheet.
Send the image to GoogleDrive as an image.

You can embed the coordinates to your image, but if you do that you cannot retrieve the coordinates as text to use in a different app.


Tim posted examples in this Forum showing how to post the type of data you want to a spreadsheet  ,  here is one example     https://groups.google.com/forum/#!searchin/mitappinventortest/google$20spreadsheet%7Csort:date/mitappinventortest/U4Cu6nRbX3c/4wmT9gJhAAAJ




Ispas Laurentiu

unread,
Jun 6, 2019, 10:53:47 AM6/6/19
to MIT App Inventor Forum
OK. I will try to do something when i will get home in 2 days and then if i have some problems i will post the code here.

Andrés Martín

unread,
Jun 6, 2019, 1:53:51 PM6/6/19
to mitappinv...@googlegroups.com
Tienes muchas opciones. 

Yo te voy a dar una forma de hacerlo de las miles posible, ok   :) 

1. Has la foto y le pones un nombre.
2. Recupera u obtienes la coordenada de la foto.
3. Envías la foto1.jpg a Google Drive
4. Envías un archivo TXT con el nombre foto1.txt a Google Drive con las coordenadas en su interior. De esta forma relacionas el nombre del archivo jpg con el archivo txt, y por ejemplo en un bucle para recuperar tan solo tienes que cambiar la extensión del archivo a buscar.

Pero bueno esto esta muy abierto, y puedes hacer muchisimas cosas y formas mas faciles o más complejas.

Bueno, aquí me tienes para ayudarte siempre, saludos, joven.

Ispas Laurentiu

unread,
Jun 8, 2019, 10:13:41 AM6/8/19
to MIT App Inventor Forum
i try to upload coordonates like this into google spreadsheet but no result ....
123r.png
1234t.png

TimAI2

unread,
Jun 8, 2019, 11:13:56 AM6/8/19
to MIT App Inventor Forum
1. Test that your google form upload routine works with some sample data
2. Check you have your spreadsheet linked to the google form to display responses
3. Test to see if you need to uriEncode the lat and long values
4. Check that you are generating lat and long values before you send to the google form

Ispas Laurentiu

unread,
Jun 8, 2019, 11:35:29 AM6/8/19
to MIT App Inventor Forum
2 and 4 checked and i uriEncode the lat and long values but still no Upload...

TimAI2

unread,
Jun 8, 2019, 1:12:32 PM6/8/19
to MIT App Inventor Forum
Test 1 then !!

You can do this with your browser and some sample data

TimAI2

unread,
Jun 9, 2019, 4:11:28 AM6/9/19
to MIT App Inventor Forum
Looking at your blocks, and then your request on my blog, you seem to be mixing two methods - using a google form, or posting data direct using the google web app method.

Decide which one you want to use and test that !

Andrés Martín

unread,
Jun 9, 2019, 5:19:31 AM6/9/19
to MIT App Inventor Forum
Sinceramente si has elegido poner la coordenada en una hoja de calculo, te has metido en la peor de las decisiones pero como siempre digo. Que tengas suerte. Hay método mas simples mas mecanizables o automatizables que ese, y con menos problemas.

TimAI2

unread,
Jun 9, 2019, 5:27:22 AM6/9/19
to MIT App Inventor Forum
@ Andres

Perhaps you could elaborate on your simpler, problem free, mechanized and automatable solution?

The reason for storing in google sheets is simply that, for storage and retrieval of data. Once the upload system is working, it is simple and straight forward.

Ispas Laurentiu

unread,
Jun 9, 2019, 5:51:43 AM6/9/19
to MIT App Inventor Forum
Yes, i tried Both methods, google form and web post, but separetly and no one has working..

TimAI2

unread,
Jun 9, 2019, 6:15:43 AM6/9/19
to MIT App Inventor Forum
Pick one method, then we can go from there. Share your blocks and your google script for analysis.

Ispas Laurentiu

unread,
Jun 9, 2019, 6:24:40 AM6/9/19
to MIT App Inventor Forum
Ok, because last i tried was web method let s focus on that . This is my blocks and script that i use. I mentioned that i save the script and google sheet to have public acces
script.png
true.png
true2.png

TimAI2

unread,
Jun 9, 2019, 6:37:22 AM6/9/19
to MIT App Inventor Forum
Remove the "&" from your latitudine text block, it is not needed, the post text block adds the "?"

blockswebpost.png


Ispas Laurentiu

unread,
Jun 9, 2019, 6:38:13 AM6/9/19
to MIT App Inventor Forum
After i make for a 10 times a new script and rename my sheet name it works to send location . but like you see in the image i want to send them like them display on my app,but in sheet it apears with dot separator from first number(i don t know if i eplained corectly what i want to say but i will put 2 images to explain better).
app.jpg
sheet.png

TimAI2

unread,
Jun 9, 2019, 6:49:59 AM6/9/19
to MIT App Inventor Forum
Don't know :)

Have a look at the values you are sending, are they for some reason in that format ? If so you may need to do some text manipulation before sending (to remove the second "dot")

Ispas Laurentiu

unread,
Jun 9, 2019, 6:55:56 AM6/9/19
to MIT App Inventor Forum
In app display they look fine, but just when i send them appear that second dot... and another problem that i see is that the upload button send image to  slow . When i press Upload the coordonates are send instant and the photo need some time, or i need to press 2-3 times on upload to send just a pic .. and that it s not so ok because then i will send 3 times coordonates and just 1 pic...

TimAI2

unread,
Jun 9, 2019, 7:01:50 AM6/9/19
to MIT App Inventor Forum
Again check exactly what you are sending in the text blocks for lat and lon. There is no reason for google sheets to add these "dots". The numbers may "look OK on the app" but you need to investigate further. Use Do It when connected to the companion to check.

You need to set up your blocks so that the coordinates are only sent once the image has been uploaded. You may need to review the response being generated by the image upload, it is not robust or accurate (my fault)

Ispas Laurentiu

unread,
Jun 9, 2019, 7:08:30 AM6/9/19
to MIT App Inventor Forum
"Use Do It when connected to the companion to check." - what is that Do It that you mentioned ?

TimAI2

unread,
Jun 9, 2019, 7:20:07 AM6/9/19
to MIT App Inventor Forum

Ispas Laurentiu

unread,
Jun 9, 2019, 7:37:07 AM6/9/19
to MIT App Inventor Forum
ok, it s a little to much for me :)) i am new to this and i try to make some app for my college. At first i think that will be easy with ai2 but now i am not so sure anymore :)) About set up my blocks to send the coordinates only when the image has been upload i need to modify the button Upload for that or ?

Ispas Laurentiu

unread,
Jun 9, 2019, 8:09:15 AM6/9/19
to MIT App Inventor Forum
So.. for now i want some help with that dot.. i can t know how to make to put the value of lat and long like they are displeyd on the app interface. So if some one can help me with that ....

TimAI2

unread,
Jun 9, 2019, 10:41:13 AM6/9/19
to MIT App Inventor Forum
We should be able to simplify and send the lat/lon data with the image information all in one go, adding the lat/lon and file ID for the image all to the spreadsheet at the same time.

From what I have seen, this is your workflow:

  1. User takes a photo using the device camera
  2. The photo is displayed in the app
  3. At the same time the app captures the current latitude and longitude of the device, this and the address for the co-ordinates is shown in the app
  4. On button click, the image is uploaded to google drive, and the location data and file ID is recorded in a google sheet

  5. User will probably want to retrieve this information in order to view the photo and see the address or a location on a map (with a marker/infobox) ?
If you can confirm this, i will see if i have time to work up an example. The Ai2 part of things is the easy bit :)

Ispas Laurentiu

unread,
Jun 9, 2019, 10:43:17 AM6/9/19
to MIT App Inventor Forum
Yes, you re right and i will appreciate if you can work on an example:)

TimAI2

unread,
Jun 9, 2019, 1:01:04 PM6/9/19
to mitappinv...@googlegroups.com
OK

aia will be attached on Edit 
Replace the script link with your own

I have done items 1-4. I used a spreadsheet with a bound script as the web app so create this using the Script editor in the spreadsheet not a standalone one.
All the data is uploaded at the same time, therefore if the image upload fails, the whole thing fails.

Latitude / Longitude / Address / File ID / Filename / View Url
All the above get listed in the spreadsheet ( i have hidden the latitude numbers and addresses )

sheetlayout.png



here is the web app code:

function doGet(e) {
 return message("Error: Please Try Again");
    
}

function doPost(e) {
  if (!e.parameters.filename || !e.parameters.file || !e.parameters.imageformat) {
    return message("Error: Please Try Again");
  } else {
    var imgf = e.parameters.imageformat[0].toUpperCase();
    var mime =
        (imgf == 'BMP')  ? MimeType.BMP
      : (imgf == 'GIF')  ? MimeType.GIF
      : (imgf == 'JPEG') ? MimeType.JPEG
      : (imgf == 'JPG')  ? MimeType.JPEG
      : (imgf == 'PNG')  ? MimeType.PNG
      : (imgf == 'SVG')  ? MimeType.SVG
      : false;
    if (mime) {
      var data = Utilities.base64Decode(e.parameters.file, Utilities.Charset.UTF_8);
      var blob = Utilities.newBlob(data, mime, e.parameters.filename);
      
      
      var imageID = DriveApp.getFolderById('1AvjKBusD5jCHttEXA24VRGVTYJIv7CyP').createFile(blob).getId();
      var lat = e.parameters.lat[0];
      var lon = e.parameters.lon[0];
      var add = e.parameters.address[0];
      var name = e.parameters.filename[0];
      var viewurl = "https://drive.google.com/uc?export=view&id=" + imageID;
      
      var ss = SpreadsheetApp.getActive();
      var sh = ss.getSheets()[0];
      sh.appendRow([lat,lon,add,imageID,name,viewurl]);
      
      return message("Success: Image Uploaded and Data Saved");
    } else {
      return message("Error: Please Try Again");
    }
  }
}

function message(msg) {
  return ContentService.createTextOutput(msg);
}

For AI2 I added Taifun's Image extension to resize the image before upload (my device was taking 8mb images!) - you can adjust the values to suit.

BLOCKS

blocksCameraLocationData.png


upload_CameraImage_Location_Data_GD.aia

Ispas Laurentiu

unread,
Jun 9, 2019, 1:10:38 PM6/9/19
to MIT App Inventor Forum
Thx a lot. I will try this tonight, and if will appear an issue i will post here .

Ispas Laurentiu

unread,
Jun 9, 2019, 1:48:00 PM6/9/19
to MIT App Inventor Forum
that link need to be replace with something ?
afas.png

Ispas Laurentiu

unread,
Jun 9, 2019, 2:15:36 PM6/9/19
to MIT App Inventor Forum
It works fine, but same problem with that format of long and lat ...
darf.png

TimAI2

unread,
Jun 9, 2019, 3:19:45 PM6/9/19
to MIT App Inventor Forum
I believe it is a locale issue (wherever you are in the world for google sheets)

This script might fix things. Add a new code.gs page to your script project and then past the script below
Set up a trigger to run this script every time the sheet is edited

function tidyCoords() {
  var ss = SpreadsheetApp.getActive();
  var sh = ss.getSheets()[0];
  var rng = sh.getDataRange();
  var values = rng.getValues();
  //Logger.log(values);
  
  for (var i=0; i<values.length; i++) {
    if (values[i][0].length > 7) { 
    var str = values[i][0];
    var res = str.slice(0, -4);
    var ser = str.slice(str.length-3, str.length);
      Logger.log(res+ser);
      values[i][0] = res+ser;
    }
    if (values[i][1].length > 7) { 
    var srt = values[i][1];
    var rse = srt.slice(0, -4);
    var sre = srt.slice(srt.length-3, srt.length);
      Logger.log(rse+sre);
      values[i][1] = rse+sre;
    }
    rng.setValues(values);
  }
}


Message has been deleted

Ispas Laurentiu

unread,
Jun 9, 2019, 3:34:39 PM6/9/19
to MIT App Inventor Forum
It's ok how i put this ? However,if it s ok still same result ..if not, what i've do wrong
fasss.png
gsss.png

TimAI2

unread,
Jun 9, 2019, 3:37:16 PM6/9/19
to MIT App Inventor Forum
Looks OK, have you made an edit to the spreadsheet, or added another row yet ?

Ispas Laurentiu

unread,
Jun 9, 2019, 3:42:13 PM6/9/19
to MIT App Inventor Forum
yes, i make new entry's with the app but same result, the lat and long still not saved ok..

Andrés Martín

unread,
Jun 9, 2019, 3:52:51 PM6/9/19
to MIT App Inventor Forum
Estupendo :) 

Si un buen lío para algo como dije mas simple con una imagen y una linea en un archivo txt.

Pero sí, efectivamente vuestra solución es correcta y brillante.

Oye es solo un broma que nadie se enfade conmigo.

Saludos a todos.

TimAI2

unread,
Jun 10, 2019, 4:50:00 AM6/10/19
to MIT App Inventor Forum
Do some work on no. 5 - to call back the data from the google sheet into your app - it might be that the coordinates come back into the app correctly formatted ?

Ispas Laurentiu

unread,
Jun 12, 2019, 4:26:34 PM6/12/19
to MIT App Inventor Forum
Sorry to post so late but i was busy with my exams these days. So that problem with the display of latitude and longitude piss me off.. i try to format the cell in text, number, custom number but nothing... This is the last issue i have with this app and i don t now how i manage it.. 

TimAI2

unread,
Jun 12, 2019, 4:36:19 PM6/12/19
to MIT App Inventor Forum
Try changing the locale of your google sheet to UK/USA

Ispas Laurentiu

unread,
Jun 12, 2019, 4:43:44 PM6/12/19
to MIT App Inventor Forum
yeah ... so simple .. thanks a lot man. I really appreciate your help here.

TimAI2

unread,
Jun 12, 2019, 4:58:25 PM6/12/19
to MIT App Inventor Forum
Yes :) !!
Reply all
Reply to author
Forward
0 new messages