Skip to first unread message

Mike B

unread,
Jan 2, 2017, 12:06:57 PM1/2/17
to MIT App Inventor Forum
Hi again all,

I have been searching for some days to find an AI2 tutorial regarding Maps and Geofencing. I have found one or two, but the links to the actual turorials are outdated, or have graphics missing. Could some point me in the right direction please...

TIA

SteveJG

unread,
Jan 2, 2017, 4:13:53 PM1/2/17
to mitappinv...@googlegroups.com
Here is the best way to work with geofences using Android:  https://developer.android.com/training/location/geofencing.html   You will need Android Studio 2 and graduate from AI2 to a fantastic, free professional compiler.

Here is the App Inventor way

 #1:  read the section   called    Programming Complex Conditions    in this article http://www.appinventor.org/bookChapters/chapter18.pdf              
   read about the caveats in the following links https://groups.google.com/forum/#!searchin/mitappinventortest/geofence%7Csort:relevance  and the power and limitations of the LocationSensor  https://docs.google.com/document/d/1V1Zm5cYoa12KVb_cTlfelSfyUkW7IH2WPHUoTa02XaY/pub   reading particularly about the property called Accuracy and the dimensions of a latitude and longitude  bounded by 0.00001 lat and lon and how small that is.

#2  Read about the ActivityStarter and the sections on locating and plotting     
   and read the Google documentation for Google Static Maps API https://developers.google.com/maps/documentation/static-maps/intro  and he example here  https://developers.google.com/maps/documentation/static-maps/intro#quick_example   ,,,almost anything in the Maps API that is shown as a url can be replicated with AI2  using the ActivityStarter VIEW  calling a url built with the AI2  join text blocks. You can actually display your geofence on a static map using either polygons or lines.   Is it easy to plot a square?  Not really.  You have to calculate how to determine the boundaries using geocoordinates to plot the geofence region.   Be aware a 0.00001 x 0.000001 degree square  is beyond the resolution of the gps in your device.

Here is how to replicate the  quick-example in AI2 simply using either the WebViewer or ActivityStarter




Of course, you will have to add your own bells and whistles.  Yes, you can plot your actual location from the location sensor.  Just add a LocationSensor , lots of blocks and your imagination.


#3 and or read about Fusion Table Maps . (You can do this  https://support.google.com/fusiontables/answer/2527132?hl=en       with AI2 too.

Regards,
Steve
                            








Juan Antonio

unread,
Jan 2, 2017, 5:40:13 PM1/2/17
to MIT App Inventor Forum
Hi Mike, in this web there are two apps about geo-fence, web is in Spanish but you can load code .aia to English...


This post is about experimental Services in App inventor, depending on whether you are on one side or the other of a latitude, a Notification comes out.


Regards.

Mike B

unread,
Jan 3, 2017, 3:42:31 AM1/3/17
to MIT App Inventor Forum
Thanks guys. Will read and explore all of those suggestions...

I notice that in SteveJG's blocks, he calls a static map. What I am after is this scenario. I am making an App for Food Truck Vendors and Food  Truck Diners. I have completed those Apps, and they are working well. As an addition to those Apps, I would like to make an App for our Local Government (Council) inspectors whereby a Food Truck enters a Council Area and sets his location to say he is trading at that location. Most of the preliminary work for that is done, as it is a replication of blocks in the other apps.

What I need to do now is to separate individual Council areas within the city I live (Adelaide, South Australia) and keep a record of the geolocations of their boundaries. All of those Councils (26 I think) will be in a list and then picked to show who is trading within their area. Hope this makes sense, and that Geofencing is the way to go

TIA

JimP

unread,
Jan 3, 2017, 6:49:47 AM1/3/17
to MIT App Inventor Forum
Hi Mike,

I'm not familiar with Adelaide so don't know if the attached shows sufficiently small geopolitical boundary units, but will still serve to illustrate the principle.

Attached is a screenshot of a map generated in QGIS - free of charge from  http://www.qgis.org/en/site/ - overlaid with shapefile [.shp] data downloaded from https://data.sa.gov.au/data/dataset/local-government-areas as black lines.

You can either export .kml from QGIS or, apparently, download .kml directly from the Data SA website to give you a CSV list of lat-lon pairs that define the boundaries of the areas. How you might then figure out if a particular truck's location is within a particular boundary shape is beyond my knowledge - perhaps others can advise.

For simplicity, assuming a truck would have live internet access to a database, could it not just report its position on arrival to site as 'Council area #3' (from a ListPicker or similar) and log its lat-lon so that the inspectors can find it?

Jim
AdelaideMap.png

SteveJG

unread,
Jan 3, 2017, 9:02:21 AM1/3/17
to mitappinv...@googlegroups.com
@ Mike   A geofence will work with AI2  to do what you want to do provided the council areas are squares or rectangles. If the area is a polygon, the problem is more complex.  If a square or rectangle you could use a different geofence for each as per the example in Wolber et al's book...perhaps   determine truck location, then check if in square A if not is it in square B etc and use that to determine whether the truck is within one of the council areas.

 There are mathematical algorithms that can determine if a point is in a polygon or not and if you have the coordinates of the outline of the council area you could try that approach. 


a .shp file (shape file) can represent any polygon, is a professional way to handle geographic data and is more difficult to work with.  If you have .shp files of the council areas you could use a Fusion Table Map and use the sql features to determine if the Android is in a specific council area.  This works.  I have done it with AI2 for US counties.     The FTMap can work with kml files.   .shp files can be converted into kml files and displayed on a FTM (described in my previous post).  This is complicated but works extremely well and is essentially a geofence. There is a 'converter' on Google's FT but the instructions are vague. Most of the difficult work is working with the FT outside of AI2...you need to get it into the appropriate form.
-----------------------------

@JimP ... shape files are a great idea for Mike's app now that we know what he actually wants to do and you suggestions are a huge  head start for him if the government area shape files include his 'council areas.'  .... Shape files can be handled in a Fusion Table and displayed on a Fusion Table map and the boundaries are in the correct form (.shp files).


------------------------------

Jim's  suggestion " just report its position on arrival to site as 'Council area #3' (from a ListPicker or similar) and log its lat-lon so that the inspectors can find it?" is probably the easiest solution to do what you (Mike) describe and requires the simplest coding.     Let the vendor determine whether they are in council area whatever and report they are there AND report its latitude/longitude   or  CurrentAddress.     Post the information to a FT used/shared by   the government,the vendors and you and the vendor can also post his/her location on the FT map automatically if you write the blocks Mike   or    the info could be sent as an email or an sms.  Your app, your dilemma, your solution. :)

Alternatively  ALL the locations can be posted to a Google static map and shared with whoever (see the blocks provided above. A limitation with the static map is the location labels can be only a single character.  You will have to provide a vendor 'key' or legend.

Good luck.  Let us know how it goes.  When you have an interesting solution, you may want to share it with the users here.

Regards,
Steve

Mike B

unread,
Jan 3, 2017, 8:55:52 PM1/3/17
to MIT App Inventor Forum
Wow!!! Huge amount of info there. So much to learn. @JimP The map you show with the Council boundaries will indeed help. I have not done any work as yet with [.shp] or [.khl] files and I guess i'll have to do some tutorials on them.

@SteveJG: I had a look at Android studio prior to deciding on AI2. I relooked at it after your post, and it is beyond me at the moment. I know AI2 has its limitations because it is primarily a learning tool. But that is exactly what I am doing (learning).

Also I have not done any work with fusion tables, and will have to look at them also.

I think the Apps that I have completed already would be of great help to a novice, and if I can progress to get this Council thing working, then it will make a great tutorial for anyone wanting a GPS solution. I will gladly share it when done.

I'll do more reading as time allows, follow all of your links, and get back to you as things progress. I think this will make a good and informative thread. Thanks to you all...
Reply all
Reply to author
Forward
0 new messages