What would be the best way to do this?
I have an application that gets two values about each and every 10th second (when user touches the screen). From this i get two values, latitude and longitude of a sphere object that the user has touched.
Now I would like to compare thoose values to values from a file, with the real latitude longitude of a location and then compare thoose values and se how far away the user was.
My file will be built up with two values and one key (location) in each index.
What would be the best way to do this, would it be to read the whole file in the beggining with a bufferedInputStreamReader and store thoose in a
HashMap<String, List<Float>>
or would i be better of using some kind of database structure like SqlLite?
Since Im doing this on a mobile platform performance is quite important and that's mainly why i ask this question.
Depending on the size of the data you need to compare against, you could either look up each time against a database (slower) or do a binary search in memory (faster).
If you store in a HashMap (for the in memory method), then you will need to sort and implement a binary search for maximum speed. Otherwise you will be searching linearly (iterating) throughout the collection of values (that might be acceptable to you).
I would say if you have a few thousands entries, then do it in memory, if you have more then go down the database route.
Related
I'm working on a program that requires metadata information in order to populate some arrays. Let's say I have information like "Countries", "Districts" and a bunch of other metadata. That information is stored in a sqlite database. The program at some time need to load all the countries and iterate them in order to search for one. My question is: What is the best way to proceed: Keep the metadata in an array after query them, or every time I need them I should query the database?
Here's some more information so you can evaluate the performance:
Metadata tables (like countries): ~10
Estimated times I need to iterate the metadata: several (~100)
the arrays contains aprox. 5 fields (primitive types.)
If the amount of data is so large that if affects the amount of data available for your other data or for other app, you should keep it in the database and access it dynamically.
If the amount of data is rather small, and it's queried rather often, keeping it in memory is more efficient.
If the amount of data is rather small, and it's queried not very often, it will not make any noticeable difference what you do.
Your particular case is one of these three, but the only way to find out is to measure the performance yourself.
I am developing an indoor positioning app based on fingerprinting approach. I am stuck at the point where I should store the wi-fi rss values in the database in the training phase. Since rss values vary significantly, will storing the absolute rss values lead to large errors in localization?
I have read many articles and http://www.csd.uoc.gr/~hy439/papers/WILL-pre.pdf says the absolute rss values of each AP varies but their difference relationship maintains. The author introduces a concept called Rss Stacking Difference which is the cumulative difference between one AP and all other APs. Can i store this Rss Stacking Difference in the database rather than absolute values?
Thanks in advance.
Why you do not try to collect several RSS from each reference node for each cell or interesting position (depends on how you segmented the map). That will mitigate the fluctuation of RSS values. then by taking the mean value for each reference node, you will have several mean values for each position or segment. Then you determine the position based on the minimum difference between the data sets in the database and the collected values in online mode.
let the position at point (x=100,y=120) associated with the following finger print
{mac1=xx:xx:xx:xx:xx:xx,rssaverage=-47.54 ; {mac2=xx:xx:xx:xx:xx:xx,rssaverage=-60.1 ; ...}
and the collected values in online mode will be structured in the same way and compared respectively.
I hope that can be helpful
good luck
i'm trying my first android app and it should track my route with gps coorinates.
The app also has a five textboxes, each with about 30 chars user can type in.
Coordinates should be saved all 30/60 seconds, is this enough?
Or is it possible to save it with 10 seconds and what's the right way to save it?
Thought about reading xml from url, but I think it could be more data in future.
What could be a good way to store it on sd as XML or normal file locally, which I can parse from client-pc to retrieve coordinates?
Thanks for your time.
Best Regards
You should only save a position if it's far enough away from the previous position. That way you'll have way less data without losing any information (in other words - it doesn't help to save the same position every 10 seconds).
In my sports tracker app, I save the data in a database table (latitude, longitude, timestamp ... basically all you get in the Location object).
XML would work but the performance would dramatically decrease as the amount of data in your file increases. I had a similar project a year ago and I used a SQLite database.
The period you want to use depends on your needs, getting a location every 10 secs might be a lot, you might want to adapt the period to the speed or the area (city or highway). You can also rely on 3g (network instead of GPS) to get accurate, quicker and cheaper (in terms of battery) location fixes in dense areas (cities)
Consider the speed of the host, and the accuracy required when reconstructing the path. If you're walking, a sample every 30 seconds might be fine, but if you're in a car, you might want to sample faster. Also, I'd suggest XML, and I'd recommend looking up the GPX format, that would give you portability as well, because other programs will understand it and allow import/export.
I am working on a Text-Based RPG for Android (just built around the default views and buttons) to get a handle on some things before I launch into a more graphically intensive game. There is a Player who moves around Locations, and each Location has a set of possible Actions. The Locations and Actions have Strings for name and description, which are displayed by textViews.
My question is how to store the multiple Locations and Actions for the game? In its current state, I'm just calling new Location() multiple times in onCreate(), but with the 50 or so I'm planning on, the code would be massive, and I'm sure there's a better way to do it. I've thought about subclassing Location for each specific location, but that would be just as bad. I've also looked at JSON, and using an SQLite Database, and I'm sure there are other valid approaches as well.
Does anyone have any links, or suggesting for storing these "plot" related items?
If I understand correctly, at this time, you have the Location object initialization code - and the required data hard coded - in the onCreate method. This is a fairly good solution for a prototype, but if you want more, you have to outsource the data and lazy-initialize the Location objects when required.
If you are not planning on modifying the Locations, than I would suggest JSON, or even easier: an own text based protocol, that is easy to parse, and store it in files of the assets folder. For example like this:
LOCATION 14 Kitchen
LOACTION_DESCRIPTION Entering the kitchen you smell the freshly cut tomatos on the table...
ACCESSABLE_LOCATIONS 13 10 24 54
AVAILABLE_ITEMS 56 23 12 8
...
And you can parse the file line by line with a BufferedReader, building your object.
If locations contain information that may be modified and the modifications should be stored persistently, then you have to use a database. There are lot's of tutorials. This way you can save modifications.
I am looking into writing an Android app that has a database of approximately 2000 longitudes and latitudes which are effectively hard coded.
I assume that once my app is installed, I can put this information into the SQLite database, but how should I distribute this information when the app is downloaded?
One option I thought of was some kind of Patricia Trie to minimise the size of the data (the points will be in a number of clusters, rather than evenly distributed), but I'm not sure whether such a collection would work when there are two associated numbers to store, along with perhaps some other information such as place name.
Does anyone have any thoughts, input or suggestions?
Rich
2000 ints is not many.
In fact I recently tried to load up my web app that has similar numbers for lat lon. I realized i need to optimize a bit, but its load time wasn't completely terrible.
You may want to just request the data you need at any given moment. There must be some other data associated with the lat lons that can help you with that... or maybe you should only display pins within some boundary of lat lon, like +1,-1 in every direction of the center of your map or something.