2014년 11월 30일 일요일

Location Sensor Problems

So i've been working on some sort of scavenger hunt app. So in this app I added a map so user have to go to a specific location for the question to show, however the issue that I am facing is that the location sensor doesn't seem to catch the current location of you user! I've tried many different way to make it work, but couldn't find a solution! I think there must be something to do with my coding because the location sensor works on Google maps (externally) just not on the App Inventor app. I've added some pictures of my blocks if someone could please assist me i would appreciate it! 





Is there a reason why you're starting this app in AI Classic?  AI CLassic will go away soon.  You really should be using AI2... The correct link for MIT's App Inventor 2 is: http://ai2.appinventor.mit.edu/

I think you'd be better off doing your work in AI2... 

I don't have the answer to your question, but it would be easier if you were doing it in AI2... AI2 is now more reliable...



Like Enis, I am not an AI Classic programmer.

There are two simple ways to establish whether you reach your destination.    One of the ways is to create a boundary box using latitude and longitude, if the LocationSensor reports a combination of latitude and longitude that is within the box, you have reached your destination.  This chapter of the free AI2 programming eBook shows how, but with AI2 blocks; the AI Classic solution is the same but the blocks will be very different  http://www.appinventor.org/Chapter18  

A second way is to use the LocationSensor.DistanceInterval.  It is discussed in the LocationSensor tutorial here:Exploring with Location Sensor in AI2    It is a property that can be used to sense when the device approaches within a programmed distance (measured in meters) from the device's location.

It is not possible to reliably   just compare the latitude and longitude from the  device with the location of the Scavanger Hunt 'find' by comparing the Latitude and Longitude for a number of reasons.
1) It will be extremely difficult for the device to find the EXACT longitude/latitude   because of inherent inaccuracies in the GPS receiver and within the satellite fix.  A gps requires knowing ephemeris data from a minimum of three satellites.  When this happens, a property called Accuracy (and discussed in the LocationSensor tutorial) comes in to play.  The larger the Accuracy value, the less accurate the satellite fix...possibly what would occur if the gps used only three satellites; however the more satellites used in a fix (many gps receivers can 'find' a dozen or more) the lower the value and the greater the precision of the fix. So, the Android device never PRECISELY reports  its location anyway.  It can easily be from two to fifty meters off, depending on the number of satellites used and/or whether the Android is not under trees or between buildings.
2)  If you compare a latitude to five digits 33.12345 for example with the latitude for the sensor which might be 33.12346 for example... the device would be only inches away from an exact match but the device would not tell you it is a match.  Consider,  0.00001 of a degree of latitude is 0.006 of a nautical mile, or 3 feet, 7+3/4 inches

I did not closely look at your AI Classic code, so I am not sure you used a reasonable algorithm to determine if the device has arrived at the proper location or not.

Either of the two methods above can tell you approximately when you arrive at your goal, but consider, depending on Accuracy at the moment the determination is made, you might be 40 to two meters wrong.  If things are right, draw a box around the hunt 'find' that is about 5 meters on a side, and go for that.   My experience is that most gps can provide that precision if they are under a clear sky; however if the hunt is in a building, the readings will easily be 20 meters off.

You said "just not on the App Inventor app. " regarding whether the LocationSensor is working.  Be aware, early versions of the locationSensor required that  users to set LocationSensor1.Enabled to true   to start the gps, also you need to set the Provider to  gps  .       Have you tested the gps with a simple project, just showing the current latitude/longitude ... is the gps working with AI for you?        Also, be aware if you are in Europe or elsewhere where the commonly used decimal separator is a comma ( , ) rather than a period (.) you will have issues programming..there are issues.  Are you using a comma where    30.567 value is 30,567 when doing mathematical operations on your device?




The reason used AI Classic was because i personally found it a bit easier than AI2 and that two this is my first time making an app so many of the tutorial i was looking at online were from AI Classic! 



As you said that AI Classic Will be going away soon is there any way i can put my AI Classic App on to AI2?! 




They're supposedly working on a conversion tool, but it's doubtful that it'll be a complete conversion.  If I were you, I'd start redoing it in AI2 now.



My LocationSensor.DistanceInterval is set to 1(Not quite sure if the higher the number is better or vice versa). and do you have any examples of where to set the Provider to gps. Sorry I'm not very much advance in programming as i said in one of my replies this is my first time. I noticed it works well outside, however not in building's is there any way that you know of that i can make it work in buildings accurately? 



Thanks Enis for letting me know, i guess your right, just to be on the safe side! Thank you! 



To make your AI Classic and Ai2 app, you have to manually convert the project.    Yes, this means start making the blocks all over again.

MIT said in late September  an AI to AI2  transfer tool might be available Fall 2014.  There are huge changes going on at the moment regarding AI2 that probably could set that timing for the tool back indefinitely as AI2 goes from Android API 3 to Android API 4.       Be aware, the 'converting'  tool DOES NOT EXIST yet.  When or if the tool does become available,  the tool probably will not provide a seamless conversion.   Everything probably will NOT convert and the users may have to make a lot of manual changes to the 'converted' app to get it to run properly.  Using the tool that is contemplated might be more difficult for some developers than programming their AI apps in AI2 manually.

The moderators recommend users do not depend on the tool and start converting their AI Classic projects to AI2 manually NOW.    Yes, that is a lot of work.    If you depend on a vaporware tool, you will be disappointed.

To help with a manual conversion, here are some links that may help your manual conversion:

At the moment the only way to do the AI Classic to AI2 conversion is to manually recreate the app from Classic to AI2.

Here are two documents that will help.  The first is a comparison of Classic Controls compared to the new AI2 controls and some advice on how to convert:   https://groups.google.com/forum/#!searchin/app-inventor-developers-library/Classic$20/app-inventor-developers-library/BFtMa0BpJq8/tY_9ZCXbtH8J

The second is a summary of the new features in AI2 and in some cases, the controls from AI they replace  http://appinventor.mit.edu/explore/ai2/whats-new.html  



Thanks for letting me know Steve ! looks like i have lots of work ahead of me! ughh! bt Thanks Again



My LocationSensor.DistanceInterval is set to 1(Not quite sure if the higher the number is better or vice versa). 
A DistanceInterval of 1 is one meter.      A better setting would be possibly 5 or more and 20 might be even better.  Why, because when the gps is used the property called Accuracy varies and if your device is under trees or obscured by tall buildings or inside a building Accurcy is going to be poor.    One is too small...try at least 5.


and do you have any examples of where to set the Provider to gps.

set LocatonSensor1.Provider to     gps      where you type the gps in an open Text blcok

 Sorry I'm not very much advance in programming as i said in one of my replies this is my first time. I noticed it works well outside, however not in building's is there any way that you know of that i can make it work in buildings accurately? 

Work better in a building... yes... stay close to the windows.   The gps receiver has has a difficult time getting a signal through walls and roofs.   The gps resolution in many buildings is terrible with most phones, it can be very good out side.



Thanks Steve that answers most of my question I'll try it out and let you know! Thx for the reply and descriptive info! 



To save yourself some coding, you might look at two of the AI2 tutorials.  Where Is My Car    and the LocationSensor tutorial here  http://appinventor.mit.edu/explore/ai2/tutorials3818.html?&page=2

Seeing them may help you with your blocks.



The default time interval is usually one minute ... that is input in ms,,, where one minute is 60000  .        1000 ms is one second.   The sensor takes between 5 and 20 seconds to get a new satellite fix...it takes longer indoors and when first turned on.

so a value of less than 5000 ms makes no sense at all.    In my projects, I use one minute... some gps navigation programs refresh avery 10 seconds or so...however, when you do that, you rapidly deplete the Android's battery.   Really.



Thanks very much for you help Steve! That clear a lot of thing up for me for the location sensor! But since I gotta recode onto AI2 hopefully some part such as the "LocationSensor.Provider". 


댓글 없음:

댓글 쓰기