Skip to first unread message

Charles Schwedes

unread,
Jun 5, 2017, 1:42:48 PM6/5/17
to MIT App Inventor Forum
I've tried using a number of dimensions to determine x/y points in Canvas Draw. No luck so far! I know:
1. My phone is about 300 pixels wide and the screen is about 2.75 inches.
2. I'd like with point to point to draw about a 10 pixel line.
3. Walking with GPS, using a timer to compute new points and know 10 meters is equivalent to .00009 degrees at my latitude.
The various approaches I've tried so far have been unsuccessful. Any ideas? Thanks. Charles

SteveJG

unread,
Jun 5, 2017, 3:00:44 PM6/5/17
to mitappinv...@googlegroups.com
You seem to be attempting to make an offline map displaying your path.  Is that true?

1. My phone is about 300 pixels wide and the screen is about 2.75 inches.
OK...its screen is probably 480 x 320 pixels-- a 'standard' screen size.

2. I'd like with point to point to draw about a 10 pixel line.
You have a tool that will allow you to draw a line 

DrawLine(number x1, number y1, number x2, number y2)
Draws a line between the given coordinates on the canvas.

The block does not draw a line of a predetermined length.

Instead of drawing the line, you could use ImageSprites that would plot to the WorldCoordinates of a point to the CanvasCoordinates and allow that to plot the line knowing the screencoordinates of the first geocoordinates and the second geocoordinates.  How to make a nonGoogle flat map is here https://groups.google.com/forum/#!searchin/mitappinventortest/non$20google$20map%7Csort:date/mitappinventortest/JSAMiqATyx4/2--sTsz5AgAJ   The link shows one way of 'converting' or scaling data to plot on a canvas

3. Walking with GPS, using a timer to compute new points and know 10 meters is equivalent to .00009 degrees at my latitude.

The link described in #2 has routines to transform World measurements (the separation (distance) between the latitude/longitude of a point you just left and a point where you are) to Canvas screen coordinates -- needed to 'scale' the Canvas to the real World.   If you plot points, you can plot the lat/long directly to the canvas 'map' using sprites or the Canvas.Draw block.

This link shows how Canvas coordinates are setup (see 
--the first part shows how the x,y points are numbered on a Canvas)    


Showing a path using a technique like this is terribly convoluted and involved.   Much easier to use a Google Static map and plot geocoordinates .. yes, you need a network connection to plot the map. You could do something like https://groups.google.com/forum/#!searchin/mitappinventortest/google$20static$20map%7Csort:date/mitappinventortest/hFV5Qw5SkkE/-qGSkEmtDgAJ   or  https://groups.google.com/forum/#!searchin/mitappinventortest/google$20static$20map%7Csort:date/mitappinventortest/lFm8msljr5M/WltUjHJRAQAJ

Also see  the breadcrumbs tutorial that might be useful .. never tried it http://kata.coderdojo.com/wiki/AI2_Breadcrumbs_Tutorial  or a Classic App Inventor Project that would have to be converted https://sites.google.com/site/seanschuettesappinventorsite/mod3/breadcrumbs ( I have no idea if it can be converted to AI2).



Regards,
Steve






Charles Schwedes

unread,
Jun 5, 2017, 4:20:15 PM6/5/17
to MIT App Inventor Forum
Steve - Thank you for your response.

Sorry my previous comments were a little too concise. Let me expand the background to my problem with an example. I would like to walk around our park and sketch, line by line, start to finish. My walk includes my 'Location Sensor'  and a clock that fires every 10 seconds, about 10 meters,  will record the Lat/Long of each interval. I'd hoped to use the lat/long of each point (actually the 'xy's for this point and the previous one) to a x/y 'Draw Line' component to shown the desired sketch. Before attempting to create this sketch I used Web Viewer and the above lat/long to create a sprite that moves along each time the clock interval.

Note: Is it possible Draw Line can't connect multiple lines? 

Anyway you now know my plan. I'll check up more on the links you gave me, Thanks. Items 1 and 2 I gave you previously described the dimensions I thought necessary to transpose from a flattish world to the screen on my phone. If you have any additional comments I 'd certainly appreciate it. Thanks & Cheers Charles

SteveJG

unread,
Jun 5, 2017, 5:33:16 PM6/5/17
to MIT App Inventor Forum
DrawLine can connect multiple lines.  The x,y, of a succeeding line must be the x1,y1 of the previous line.  Unless you specifically 'erase' what you draw persists..

Yes, I understand what you want to do.  I don't want to say impossible ...it is a matter of scaling and the tools you might need are described in the previous post.
If you use a Google Static Map,the lines that connect the points every 10 seconds are called polylines; when you use them to show walking progress, they are called a trak.
When you fire a LocationSensor 'every 10 seconds' you might not get a satellite fix and if you get a fix the LocationSensor Accuracy might be such that it is 50 ..that is 50 meters or it could be 4 or 5 meters, seldom less than that because the GPS in an Android phone is not very precise..  What position is reported by the LS might easily be off by ten meters or so.  You probably have read and done the two examples in      Exploring with Location Sensor in AI2
The location sensor object is used to communicate with the global positioning satellite receiver (GPS) in your phone/tablet. When the LocationSensor communicates with the built-in GPS receiver, the GPS can determine the location of your device.  The sensor can also work with network/wifi location services.  Finding a location using the network uses very different techniques to determine a location. Location means, the device's present latitude and longitude or it can mean your street address. .  Do the accuracy example, or download the aia again and see what happens with the raw GPS data you are trying to generate that is the basis for your plot.  The example  presently posts GPS coordinates I think every minute; change the timing to 10 seconds and see what happens . Depending on your timing (and actual coding) checking every 10 seconds will not give you the precision you hope for and may actually introduce positional errors.

Anyway, have fun.
Reply all
Reply to author
Forward
0 new messages