Displaying Annotations on Map on viewing region only with Titanium SDK - android

I have locally stored about 1200 anotation data in an array. Now I want to add/set only annotation to region that is presently viewing. When user updates the region this will add/set new annotations. I know we can implement this in regionChanged method. I want this to be loading fast. Please suggest me how can we implement this that will be efficient. Also please suggest me which will be fast enough Loading annotation in single time with
mapview.setAnnotations(annotationarray);
or showing as region wise. The default zoom level of application is as this will have only 2-4 annotation at a time. sorry for multiple question in single time.

With your current region and the latitudeDelta and longitudeDelta you can deduce what your current map bounding box is (that's the coordinates of the 4 corners of your current mapview).
You should check if the coordinates of each of your pins is within the bounding box and then if it is inside save it in a separate array. Once you finished the check add that array of annotations to the mapview.
Each time the region changes you should repeat this operation.
I don't know how efficient this solution is, but iterating through an array of 1200 items is not going to be inexpensive.
If this solution is very slow, you could also save the coordinates in a sqlite database and execute a query each time.

Related

How to smooth out discrete data-points to look continuous?

I have two ArrayLists with double data. I am already using moving average smoothing. Data is collected every 200-500ms. This is what a typical graph (using GraphView in Android) looks like:
Since the data collection rate is limited by the hardware I am using, this is how jagged the result looks. Very easy to see individual points.
How do I make the function look smooth and continuous (either mathematically by altering the ArrayLists or by changing some setting in GraphView?
Is polynomial fit the way to go, or should I use a combination of filtering and moving average?
I appreciate it!
It depends on how you want to smooth out the functions. Your problem is that you do not have enough data points to make it look smooth since graphview draws a straight line between two data points. I do not think there is a way to draw a curve between two points in GraphView without using custom views. Custom view is another beast so I do not think you want to do that. There are two ways now that you can solve this problem.
First way, if your know beforehand that your data does not contain high noise, then you can perform polynomial interpolation of all the points in your arraylist. From that, you will get a function which you can use to create a new arraylist and calculate the y-values in smaller x-steps than what your data has. This way, you can simulate a curve. But do note that interpolation is costly especially as you go to higher orders of polynomials.
Now, if you know that your data is noisy, interpolation will interpolate (fit) all of the noises and that is not what you want. Then you want to use the least squares method. You can go for any orders of polynomial. Use the one that makes the most sense. Least squares will be less time consuming to compute than interpolation and it has the advantage that if your noises are bias-free (meaning the sum of the noises add up to 0), it might provide you with a better approximation of real values. Also note that in least squares, your computation becomes significantly easier if your x-values in your data are separated from each other uniformly. In your case, this could be true since you mention that you collect data every 200-500ms. If you can poll at a fixed rate, then do it. There are various equations on the internet which provides easy least squares calculations given fixed intervals.

Displaying a route on a floor plan image

I have a floor plan on which the walls are black, the doors are orange and the target is red. What I want is to make an app where given a specific point on the image, the route to the target is calculated and displayed. I already have a routing method, but it is in matlab and each position and object is defined in the code and it doesn't use an image. What I would like to know is how to scan the image to identify the walls, the doors and the target by color in order to apply the routing method and then display the route over the image of the map (I guess I should use drawable for that).
This are some steps to implement a pathfinding algorithmm from an image.
Upload your image
Apply a color detection HSV(in the real life is most easy control the
light changes with this format) algorithm to obtain the objects
separately.
Make a new binary Matrix with 1 for your floor and 0 to the
obstacles.
Apply to that binary Matrix an Occupancy grid algorithm(this reduce
your matrix because in the pathfinding algorithm you need
processing).
and now ur path finding algorithm. I recommend use the diijistrak or A star algorithm, in this two cases
you need construct an adjacency matrix.
The graph theory will help you to understand better.Good Luck!!
You can work in processing IDE for rapid prototipyng and migrate all the processing IDE core to eclipse, you need implement the PApplet class in your eclipse project, and can compile your app to Android.
I would use somekind of occupancy grid/map where each grid cell = one pixel (or possibly a small collection of pixels like 2x2 3x3, etc) And just do k-means clustering on the image. There are a few choices for k
k=2
you have walls is one group (the black lines)
everything else is considered opened space (this assumes doors can be opened).
You will need to know where the red point is located, but it doens't need to be visible in your map. It is just another open space in your map. that your program internally knows is the endpoint.
k=4
a group for everything black=walls(occupied), orange=doors(may or may not look like occupied cells depending on whether or not they can be opened),red=target(unoccupied), white=open space(unoccupied).
In both cases you can generate labels for your clusters and use those in your map. I'm not sure what exactly your path finding algorithm is, but typically the goal is to minimize some cost function, and as such you assign a extremely high cost to walls (so they will never be crossed), possibly assign a medium cost to doors (in case they can't be opened). Just some ideas, good luck

AChartengine: 1. repaint(), 2. limit data points

1:
I use achartengine to draw a line chart. Since i receive constantly data i want the chart scroll automatically to the right. My Problem is now, that the chart only scrolls when i touch the display of my phone(Android 2.3). Chart is running in extra thread and gets repaint() every ~100 ms.
2: How do i limit the collected data points. Is there an option to save the last 100 points and delete the older values? Currently my app saves all data points and gets slower and slower.
Best regards.
You can dynamically set the visible chart area using: renderer.setXAxisMin() and renderer.setXAxisMax(). Call repaint() after calling these methods.
Using the same APIs as the above you can control which data to be displayed. It's up to you to remove data from the series after that.

Subtract & get difference of two images(touchpaint) and get an integer value in Android

I have a requirement where the user needs to draw something on a FingerPaint like application and submits. I need to check to what extent the image matches and take the difference of the user's image with the ACTUAL image. The difference should then return an integer value. Depending on that, the user gets a score. Any suggestions is it possible to take difference of two images just like in MATLAB in Android?
At first find out the coordinates of your 1st ans 2nd image and then insert it into SpatiaLite database, it has all functionality such as union, intersection, subtraction, covexhull etc between two or more objects.
Take a look
Or search about SpatiaLite.
It will help you what you want...
Have fun...
i think you first get the ACTUAL image rect ,and record every pixel and its location. then you can get the same rect of the user pic,and compare all pixel. or use rect.contain() to found if all pixel is in the rect.if all in the rece you should compare pixel location

How to store screen objects for a 2d side scrolling game?

I'm trying to figure out the best way to store map objects on a 2d side scrolling game.
For example, in the game Doodle Jump, how do the platforms you jump on get stored?
I've had a few thoughts about how it is possibly done..
Are the platforms stored in a string or other object that defines where each platform is going to be placed? For example if I defined a string like 0,10,5,8,6,2,3,4,2,..... and so on, I could interpret those as x-coordinates of each game piece in the game. I guess the problem with this is that could potentially be A LOT of game pieces to define. The game appears to be endless, so pre-defining the map seems like a bad idea.
I also thought that maybe the pieces are just random. So whenever the map calls for a new map piece, it randomly gets an x-coordinate. I thought this seemed pretty feasible but when playing DoodleJump it doesn't appear that they are all random.
Does anyone have any idea on how these map objects could be stored to lead me in the right direction?
Thanks!
I'm thinking an array of incremental height coordinates and their respective width coordinates (1d or 2d array). Incremental because of not letting the coordinates get to big.
You can use the screensize to know which platforms to calculate screen coordinates for. When the jumping object reaches a certain screenheight threshold, shift the camera with it, calculating new screen coordinates, omitting platforms that fall off screen and adding platforms that come within view.
You could generate the array beforehand using an algorithm with some randomness with a min/max constraint on coordinate distance. When using ints, you could generate a pretty big array before getting into trouble I guess.
Or generate it real-time using the same seed for the random function, so it will generate the same array every time and you can keep going indefinitely
You could use a random number generator with a fixed seed per level so users get the same level every time. The random numbers can select from an array of appropriate values. (I've used this successfully in an android game.)
A lot of platform games store the static map platforms (that is, the parts of the map that cannot be manipulated/destroyed - the floor tiles in Mario Bros., for example) as either predefined map. This can be done using an array of values or an alphamap image.
If you use the array method, use bytes (unsigned char's) instead of int's.

Categories

Resources