I'm programming a GPS tracking system using the Motorola i335 running on Sprint's IDEN network. I'm using the javax.microedition.location api to find the GPS coordinates. To set up the updating, you use the [setLocationListener][1] method. I originally tried passing (listener,2,1,1). However there were too many invalid locations being received (where the GPS could not get the fix in the specified time), so I changed the parameters to (listener, 20, 20, 1). Now the system barely throws any invalid locations. My goal is to get the fastest number of updates that are realistic. Have any of you found a happy medium for parameters of this method?
[1]: http://www-users.cs.umn.edu/~czhou/docs/jsr179/lapi/javax/microedition/location/LocationProvider.html#setLocationListener(javax.microedition.location.LocationListener, int, int, int)
I'd rather implement a verisimilitude check to avoid invalid location data.
Checking the provider state for availability and comparing the last returned lat/lon values should do the trick.
Related
I am developing an app which will give you nearby Mosques within 10 km of your current location. Now that the Places API allows a certain number of queries per day, I have used firebase to store nearby Mosques for a certain location and I first check if the data is in database or not before querying. But this still doesn't solve the problem. e.g. if a user is on the go the whole day then the results must be changing every single minute, according to his/her location. How can I achieve the desirable results?
As mentioned earlier, I am saving nearby locations in a database with their relative location (around which they exist). But this doesn't quite solve the problem.
Any help will be greatly appreciated.
Places API is a commercial offering - you are meant to pay for using it, if you want to make applications around it.
There's a certain small number of calls that you can do for free, but this is only meant as testing grounds or private use. I am no lawyer, but I would guess that circumventing the fee by scraping the map (like setting a bot to go around a country to build a database of points of interests) would be illegal and would probably get you a letter from Google saying you should stop.
Use AutocompleteSessionToken class to generate a token and place it after your key , this token will reduce your usage because you can request the places api multiple times and still it will be considered as a single request. i hope this will help cause i didnt get your question very well. here is sample of the link:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=1600+Amphitheatre&key=&sessiontoken=1234567890.
For more details.see here
I would like to determine the distance of an object from my Nexus 5 camera, preferably without using an object like a coin for scale. I figured the Camera.Parameters getFocusDistances function would work for this.
I attempted to do this via something like the following in my takePicture() jpeg callback:
Parameters params = camera.getParameters();
Float focusDistances[] = new float [3];
params.getFocusDistances( focusDistances );
I tried running this a few times with objects of different distances from the camera, though each time, focusDistances[FOCUS_DISTANCE_NEAR_INDEX], focusDistances[FOCUS_DISTANCE_OPTIMAL_INDEX], and focusDistances[FOCUS_DISTANCE_FAR_INDEX] all contained the value positive infinity.
It's possible I'm doing something wrong, in which case please let me know if there is a specific way I'm which this will work on the Nexus 5. However the android API specifically states you can call getParameters() (and then getFocusDistances()) at any time to get the latest focus distances and therefore I think this should work. One thing I haven't tried yet is doing the above in an on auto focus handler, however I don't see why this should matter.
I did some research to try and see what was going on, and I found several questions regarding this sort of behavior from getFocusDistances() and typically the answer, if there was one, was that the function is not supported by the android API and/or the hardware manufacturer. Now a lot of these discussions I found online were from several years ago, and dispite the questionable feelings it gives me about getFocusDistances, I've still seen this function suggested to be used for getting the focus distance so I figure it must work on SOME device for SOME android API version.
Does anybody know if getFocusDistances() works for any particular version of android on the Nexus 5? If not, does anybody know ANY device it does work on?
EDIT:
Since posting, I have tried obtaining the focus distances in the onAutoFocus handler, as well as trying a bit more extensively for objects atvarious distances. The results have been consistent - positive infinity is always returned for all 3 focus distances (NEAR, OPTIMAL, and FAR). I even tried this with a Nexus 7 and getFocusDistances always returns the constant values (0.95, 1.9, and infinity), so apparently getFocusDistances isn't implemented on that device either.
Therefore, I really have two questions:
Is there any way to get somewhat accurate focus distances using the android Camera API with the Nexus 5? I'm even wondering if there is custom android version where getFocusDistances is actually implemented, since otherwise I may attempt to do so myself depending on what I find when examining the API code.
Are there any android capable devices that are known to implement getFocusDistances in a somewhat accurate manner?
First of all, It's very difficult to measure the object distance from one single shot/view. You would find many research papers which tried to employ vision based techniques to judge the object distance. I can refer you one such paper. They tried to implement a positioning system that would solely work on mobile camera+sensors. You would probably realize how non-trivial it is to measure the object distance from one single camera view. They finally used a method called "structure from motion" vision technique to calculate the distance (From multiple photos taken from multiple angle).
Even traditional apps like SmartDistance and SmartMeasure needs to use geometric tricks to measure the distance. None of them could only rely on camera parameters. Sorry for the elongated introduction. I have done a project of this sort before and I am telling you all these based on my experience.
To answer your query, I haven't found any Android device yet which returns realistic values of focus distances. They are either returned as some constant values or sometimes 0 and infinity. I found someone reporting that it worked for Galaxy Nexus but only within 30cm object distance, it doesn't work for distances more than that. The bottom line is that you cannot rely on this function from camera API which is heavily dependent on the device drivers. And, phone camera's are not well-known for their lens/sensor qualities. It would be very very difficult for you to work on any optics based formula for mobile-phone cameras. I would suggest you to rather go for some sensor based geometric tricks.
I was wondering if there is a way for me to detect if the users device is being "obstructed" by a building or roof of some sort. Im developing a very precise location based app and its KEY that my users get alerted if something is wrong with there GPS or something is getting in the way. Physical object.
EDIT: The app ive created strictly takes snapshots too its not something thats constantly going. Just a quick snapshot.
Not directly. You can try calling LocationManager.getGpsStatus and iterating over the list of satelites every so often and looking for a jump in signal to noise ratio since the last reading. Getting a working algorithm is going to take a good amount of work and testing on a variety of devices with different GPS chips.
I'm building a location based application and I would like to avoid from this kind of location: "Tel Aviv, Tel Aviv, Israel" which is very not accurate.
I use the following condition before using a location:
if(!(this.location == null || this.location.getAccuracy() > 700))
// use the location
But I keep getting this locations (Tel Aviv, Tel Aviv, Israel), and Tel Aviv is not small enough to pass this condition.
I'm missing something? What's wrong?
You haven't specified a couple of parameters involved but I'll give it a try.
The exact Location parameters depend on the source of that particular Location, i.e. how it was obtained and using what geolocation source(s). For example:
If you use GPS, the Location will have reliable accuracy values.
If you use cellular network radio stations (BTS), the accuracy you'll receive will be limited to the database of BTS around the world, their location and range.
If you use Wi-Fi networks and their reported signal strength, the accuracy will depend on the quality of the database of the Wi-Fi networks. Unfortunately such databases are not cheap to maintain and create. For example Google buys such databases and uses Google Street View cars for scanning such networks.
If you use localization based on public IP address, your accuracy will be limited to a town, because that is the most accurate information contained in IANA IP address space registry. Also, it can be fooled by using a proxy servers.
The accuracy you'll receive from a location service represents a distance (in meters) from the reported location in which the device is likely to be in the moment the location was obtained.
So (if I understand your question correctly), I presume your using a low-accuracy method of obtaining current device location. You simply must switch to a source of Location with greater accuracy.
Please also note that the location-acquiring method (i.e. the service used to find the location as described above) used by the location service might actually not be able to provide accuracy for returned Location. To understand what I mean by that consider a following scenario and their two outcomes - note that they both come from the same locating method based on Wi-Fi networks:
You are in range of several Wi-Fi networks. You ask the location service about device location. All Wi-Fi networks in range happen to be in location service DB. The location service is thus able to get your location with decent accuracy.
You are in range of several Wi-Fi networks. However, none of them happens to be well known to location service in that their origin (town) is known, but their exact location and range is not known. In that case the location service is able to tell you which country/town you are in, but has no idea on your precise location. In turn, location service can give you a location with no accuracy.
You must make yourself prepared for such an occasion by testing if the accuracy is available at all. You can do this by issuing Location.hasAccuracy(). If the returned value is false, you can't call Location.getAccuracy() (actually you can, but beware - it'll return 0!). So, your condition should be more like:
if (this.location != null && this.location.hasAccuracy() && this.location.getAccuracy() < 700) {
// do something
}
I will construct a fictional app in order to construct my question.
I write a kind of treasure hunt app where the user gets a prize if they visit several locations around town. In effect the app would get their current lat/lon and check its proximity to the list of "treasure locations", if they are within 10 meters of any treasure location they get a notification.
The app will then do a http post to a remote script which basically inserts into a database. The post parameters will be uuid of device and the location they visited.
An attacker could easily watch wireshark and get the name of the script along with the parameters. They could go further, decompile the apk and get other things such as any hashing/obfuscation. They could then just use curl to post willynilly as they pleased and the game would be ruined for non-cheaters. This is a problem have never had to really address since in all the apps I have written there is always data which isnt sensitive and I dont mind it being exposed to the public.
What do I do?
The best think you could do is to send the data in a secure manner. Using HTTPS would be a much better choice, regardless of method. This effectively prevents eavesdroppers, it is the fundamental technology behind any secure communication on the internet.
Aside from the protocol to communicate with the server, there are still insecurities. Essentially, there are three methods that could work to overcome these.
The location of the player could be sent to the server at some periodic interval. The server responds back if they are close enough to one of the areas. Perhaps the server could include enough smarts to know that it takes time to get from point A to point B.
A single location could be sent at a time to the app. The track of the user could also be uploaded, to verify that the location is correct.
The locations could be sent through a one way function to the program. The real answer could be then sent to the server. The problem with this is that the exact location would need to be discovered in order for the same hash to result back. However, as GPS coordinates tend to only be accurate to a few meters, and don't tend to give insignificant digits, then multiple values could be tested near the current location. The one-way function would have to require some time to calculate in an effective manner, as otherwise it would be trivial for a bad guy to simply test every square meter in the city to figure out what would work.
The best method from a security standpoint would be the first, as at no time does the application know where it is supposed to go, until it reaches that location. Of course, this pings the server a large number of times needlessly.