I'm new to Android development and am creating an app that allows a User to create a Geo fence around a specific location for reminders. For example: Making a geofence around a grocery store to remind the user as he enters to pick up Orange Juice.
Does anyone know of a tutorial that could help in developing something like this?
AFAIK there are no tutorials for geofencing, but it's pretty simple (assuming you want a circular fence).
This tutorial will tell you how to get the user's location
Any of these links will show you how to calculate the distance between their current location and the centerpoint for their fence
Calculate their distance from the center at regular intervals. I'd let them set the interval through a settings screen and start with a default around five minutes because anything more than that is a hefty battery drain. Store that distance every time you get it.
If their last distance compared to their new distance crosses the boundary, perform your action. For instance, I worked on an app that would alert a parent if the child left a friend's house or arrived at school.
An new API called Proxim.io was recently developed that serves your purpose. The website is www.proxim.io. Here is a quote from the developer documentation:
Proxim.io is a platform for delivering relevant messages to your application users. Messages that are delivered based on real-time location, topics of interest, and geo-triggers. Messages can be delivered to a device via Push, or can be routed to a software system through an API (Web Events).
Related
I'm developing an app that tracks walks, bicycle rides, car rides etc. I need precise info, so I basically would like to use only GPS. Still most sources I found recommend using Googles fused API e.g. for power saving reasons, so I went for the fused API.
Now once in a while (once or twice a month) I get one freak value among thousands of good ones. a few of them I got near railway stations, where the freak value is at another railway station, several kilometers away, so I assume it is a wrong interpreted WiFi based position.
Here's one example, where I ride my bicycle from the river towards the main railway station located east of the river. Once I arrive at the main station, I get no position for 126 s (I asked for every 10 sec, so I probably lost the GPS signal), and then suddenly I get a freak GPS value at another railway station 3450m away on the other side of the river. The reported accuracy for the freak value is 20 m.
The problem is that I cannot easily identify and filter these freak values.
Calling currentLocation.getProvider() always returns "fused", which is not very helpful.
Also Location.getAccuracy() returns typical values below 100m.
So today I filter based on evaluating speed combined with unrealistic changes in bearing, but I'm afraid I might also discard good samples in the process.
I scanned a lot of Stackoverflow, but strangely enough I didn't find any relevant answers yet.
I now feel like moving to the old framework location API and use GPS based data only. But is that really necessary, or does anybody have an idea how to avoid getting the freak values, or alternatively how to easily identify and discard all wifi based positions?
And will using the framework location API have bad battery life as a result?
I was building a prototype of vehicle routing application using google maps and optaplanner. I change the distance based scoring to duration based scoring, where the duration value was calculated using distance / avg speed of vehicle.
Now I want to add traffic jam variable into my application. The traffic jam variable was implemented as additional duration value from the current location to another location (I using a map of location and double just like distance variable in RoadLocation class). When I tried it to run it, the result was always same with the previous one. Here is the result from the first run :
I draw some red line to represent the traffic jam, and then try to re-run the solving phase. Here is the second result:
The result was the same with the previous one. My questions is, what the best method to apply the traffic jam variable into vehicle routing problem? Does anyone has any experience adding this variable? Any comment and suggestion will be appreciated.
Thanks and regards.
This paragraph is just an introduction. If you wanna skip it, do it. ;-)
I have implemented a similar approach with traffic jams, but it was not a real-time system. The solution runs every X minutes, which is absolutely fine.
That gave me the benefit for pre-calculating the ways and routes for the complete road network, before the actual optaPlanner calculation starts.
This saves time for the real calculation of optaPlanner.
The network consists of vertexes and arcs. For each arc you'll have a weight.
Here starts the real deal for you.
Let's assume that you implement a Dijkstra or A-Star algorithm for the precalculation step for all places and how to get there. These way finding algorithm is seleting the arc with the lowest "travelling" costs. For each arc/road, which would be blocked, we assume a distance of DOUBLE.MAX_VALUE. This value can be interpreted as "not driveable" or drastically said: This connection between two vertexes even doesn't exist for the current solution finding process. So the way finding algorithm will simply skip this road. For every driveable road, we calculate the real costs, e.g. distance or take an approximation out of experience.
The optaplanner process itself just uses the precalculated way finding mechanism, e.g. compares the calculated distances for getting from place A to place B.
For setting the distance variable to DOUBLE.MAX_VALUE you can decide between user based information, information of other providers like google or admin based rules. As my experience goes along with user based content vs. admin based actions, I can recommend both ways.
Let's discuss the user based action: The user can have the same set of GUI actions as the admin for flagging a way as "jammed". For the next optaPlanner iteration the flag is going to be involved. If you have GPS data of your users you can get the approximate velocity. For each intervall of the GPS measurement you can calculate that velocity. If the velocity is on a road (not a crossing), and below a defined minimum velocity (let's say 1mph or 2 kmh), then you can ask the user if it's a traffic jam or not via popup OR block that road automatically without asking the user. If you chose the popup dialog then a lot of different users have to vote "yes" within a defined time slot, e.g. half an hour, then the road get's blocked. You can resolve the traffic jam, when a lot of users drive the road again and send the GPS coordinates of that road.
The main advantage of the automatic approach is, that you'll have a system based approach with a low error rate.
If you take the manual approach via admin, then you have to take care of implementing a GUI for displaying the roads and enabling/disabling the blocked attribute for a road.
I have to develop an Android application for educational purposes.
This application uses a smartphone's hardware sensors, especially the accelerometer.
The application must be made up of several "modules"(which could be for example background services), which all need to access to the same data from the accelerometer in real time, so that each module can use the data to make its own calculations.
For example, suppose I have an activity/an user interface, from which I can choose which services I want to start.
For simplicity, suppose I have just two services, and I can choose to start just the first one, just the second one or both.
The first service reads data from the accelerometer and writes all of them into a text file;
the second service, instead, uses accelerometer's data to calculate the magnitude of the acceleration and, if it is greater than a given threshold, it writes the amplitude in another file, otherwise it does nothing.
How can I do to make that the two services share the same data?
Should I put the data in a buffer or something like that? It is possible that I have to collect accelerometer's data for a long period, for example 8/12 hours at the fastest speed.
I don't have any clue of how I can do.
Could you help me please?
Many thanks
I'm new to android programing. I know how to get a position of a user in outdoor environment using GPS.
But i'm faced with a problem to find the location of a person inside a building where you don't have GPS available.
I can handle the coding part but i need an idea in how to use compass, accelerometer, and gyroscope data or any other sensor data except GPS to get the current position of the user inside the building after you pass the compass, accelerometer, and gyroscope data to the server. Here consider that the inside of the building is mapped.
Sorry if this is a stupid question.
It sounds like you intend to perform inertial navigation using accelerometer data based on the last good GPS fix. I think you'll find this is not feasible on a mobile phone. Accelerometers used in inertial navigation -- for example, in aircraft -- have to be extremely accurate and highly calibrated to minimize errors. Even then, all inertial systems drift over time. With the relatively low accuracy of a phone, these errors will accumulate quite rapidly and render your position solution unusable very quickly.
Without GPS, most phones can still give you a rough position estimate using cell-site multilateration. This is nowhere near as accurate as a GPS fix, but it's better than nothing.
See also this excellent discussion of indoor locationing (inertial navigation is mentioned there too):
Android accelerometer accuracy (Inertial navigation)
Indoor locationing is quite difficult, if not impossible today.
What works is mounting Low energy Blue Tooth "Beacons" at multiple places in the building,
and use that as info. (see ios Beacons) (But you have to manage that yourself, relation between beaconID and location inside bulding).
With compass, accelerometre and gyroscope you will not have (much) success:
In this Google Tech Talk video it is quite detailed explained why a gyro / accelerometer (relaive) navigation cannot work because the slight inaccuracies accumulate within 2 or 3 seconds so strong that you cannot use the result. This is cause by the double integration, see video at 23:30.
Private WLAN (inside your building) triangulation can work, but not inside an (limited) phone which does not give you the info which WLANs are vissible, at which strength.
What remains the already build it GSM-Cell or Wlan location in your smart phone for indoor usage.
There is one further approach:
Evaluating the magnet fields of an building.
This can work, and at least one company works on that, but you have to calibrate that for each building.
But this is more a reasearch topic, than a well known technic.
Further info
My Algorithm to Calculate Position of Smartphone - GPS and Sensors
I'm trying to write multiplayer game for Android with java back-end using sockets, but I don't know how to do some things.
For example, I have to players. First player pushed "UP" button and his avatar moving up. How can I tell about it to all other players?
I can send message, that user with some ID changed his coordinates to new X and Y, but I will need to do that for every millisecond while he moving. Is that right?
Or I can send message that user with some ID pushed UP button and after that new message that user released UP button. Using time difference between this two events and movement speed I can calculate new coordinates of user, but in this case will be problems with latency (time difference calculation will be not enough accurate)
How I can do that?
You can do it in lot of ways and all will have drawbacks like you already found. I guess there is no "best" way to do that.
A common way for games is to have a "game server". The server recieves input from all clients and decides about the resulting state.
Clients could for example just transmit the keypresses and the server tells them about their location and location of other clients that need to be drawn. Clients do the same math locally and display this state while waiting for confirmation from the server. But that's just a prediction.
When it lags you can observe yourself jumping between positions in a lot of games because actual server calculated position and your prediction got out of sync.
The other advantage of server-side state decisions is that clients can't cheat that easily. It's no foolproof way to prevent every cheat. Aim-bots for example simply simulate a perfectly aiming user by moving the mouse for them and that's basically not detectable. Map hacks / wall hacks (anything where you can see things that you would not see) on the other hand can be prevented by simply not telling the client about currently invisible things. Only the server needs to know the full state.
The server approach can also be used without a dedicated game server. Instead, one of the clients will have the role of the server and decide about the game state. That responsibility can in some games even switch between clients if the original host drops out. A smooth handover if that happens is rather tricky though.
If there is no server and all clients are equally responsible you will have to think about schema which defines which client is responsible for validating which action. For example in a shooter, A shoots in a certain direction, and thinks B is still there but B already moved a bit further and now A thinks "B was hit" and B thinks "shot missed" -> Either the one shooting or the one being hit should decide what happens.
A schema with multiple decision making parties might not work for every game and it is a very complicated task. Not just for games but distributed computing in general
Java and Sockets are just tools here. The actual problem is one where you should take pen and paper and think about a schema that works for your scenario.
Regarding coordinates every milisecond: you could also send messages like "I will be at point X,Y at time Z" and other clients interpolate the path of that player so you don't have to transmit every position.