Android GPS for a Square region - android

I would like to use Androids Gps to as a access point on my app. Meaning if a user isn't with in a square. how do I get Android to accept between (for example: Longitude and Latitude) 50.000 - 65.010 (with 50.00, 50.00 as my Center point or Tower). Now because I want to cover a a 4 block radius how to I get android to accept values only between C to G for both gps values. I guess I want to prevent users from using application outside of city, state, neighborhood ... a square area. So far I am successful in using Gps as a login but I am stuck at hard coded locations:
if(username.getText().toString().length() > 0 && password.getText().toString().length() > 0 ) {
//------------------------------------Username below -------------------------------------Password below ---//
if(username.getText().toString().contains("XX.408") && password.getText().toString().contains("-XX.") ) {
Any input on how I can cover a Square are would be very Thankful. Thanks in advance.

Use rectange.inside(Point).
Set origin of rectangle to SW corner (x=longitude, y =latitude)
Set width to longitudinal difference.
Set height to latitudinal difference.

Related

Pose Detection for squat with count using ML Kit

How can I get real time exercise count and angle using ML kit? Here, I check https://ai.googleblog.com/2020/08/on-device-real-time-body-pose-tracking.html for push up and squat exercise count.
I am getting angle by following method :
fun getAngle(firstPoint: PoseLandmark, midPoint: PoseLandmark, lastPoint: PoseLandmark): Double {
var result = Math.toDegrees(atan2(lastPoint.getPosition().y - midPoint.getPosition().y,
lastPoint.getPosition().x - midPoint.getPosition().x)
- atan2(firstPoint.getPosition().y - midPoint.getPosition().y,
firstPoint.getPosition().x - midPoint.getPosition().x))
result = Math.abs(result) // Angle should never be negative
if (result > 180) {
result = 360.0 - result // Always get the acute representation of the angle
}
return result
}
I have added logic from my side but still want help if any proper way I got. What I am doing checking angle every time.
I want to display count and feedback based on user doing exercise.
I made a simple demo about squat count https://www.youtube.com/watch?v=XKrZV864rEQ
I just made three simple logical judgments
The height of the elbow is higher than the shoulder, otherwise the prompt "please hold your hands behind your head"
Standing straight is judged by the angle of the thigh and calf, and the effect is currently not good.
Compare the distance between the legs and the shoulders, and the legs should have a certain proportion of the shoulder width, otherwise the prompt "Please spread your feet and shoulder width" Both standing and squatting are judged by taking the human leg length/5 as the minimum movement unit, and the minimum distance from the last coordinate. Because the distance between the person standing and the camera will affect the coordinate ratio
My english is poor, most sentences tanslated by google translate
Here are several things you could try:
(1) You need to ask your users to face the camera in a certain way, e.g. side way might be the easiest for detecting squat and frontal would be the hardiest. You could try something in-between. Also how high the camera is (on the ground, head level, etc..) could also affect the angle.
(2) Then you can calculate and track the angle between body and thigh and the angle between thigh and calf to determine whether a squat is done.
(3) About feedback, you may set some expected angles, and if the user's angle is smaller than that, you could say "squat deeper"...
(4) To get the expected angles, you would need to find some sample images and run the detector on it to get them.

Android compute right bbox for WMS getFeatureInfo

I'm trying to make a request to my Geoserver to retrieve the features near the tap of a user on the map.
The map takes all the space. Therefore I computed the BBOX in this way:
region = mMap.getProjection().getVisibleRegion().latLngBounds;
double left = region.southwest.longitude;
double top = region.northeast.latitude;
double right = region.northeast.longitude;
double bottom = region.southwest.latitude;
and the width and height are taken as belows:
mMapFragment.getView().getWidth();
mMapFragment.getView().getHeight();
while the X and Y parameter are calculated in the following way:
Point click = mMap.getProjection().toScreenLocation(latLng);
where latLng is the point that came from the event onMapClick(LatLng) (reference here: https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.OnMapClickListener).
The resulting URL that I obtain is:
http://localhost/geoserver/sindot/wms?service=WMS&request=GetFeatureInfo&info_format=application%2Fjson&version=1.1.1&srs=EPSG%3A3857&bbox=1222173.74033,5056403.44084,1222174.11356,5056403.7028&query_layers=sindot:verticale&layers=sindot:verticale&feature_count=3&styles=tabletb3lab&width=2048&height=1262&x=1441&y=503
The problem is that the server returns always an empty response even if I know that there are features there because I can see the spots on the map. What could it be?
Thanks in advance.
It onlytook to add &buffer=10 (or another number according to your needs) to the request.

Find movement turn angle using Location

I need find angle of vehicle turn measured in degrees.
Location points update with equal intervals (1 sec). Therefore device makes like 4-5 points during turn. I schematically displayed that on picture.
Is it possible to calculate the angle of turn using Location? If it is possible, how?
What I tried:
Create two geometric vectors from points 3, 4 and 1, 2 respectively and find angle between those vectors. Coordinates of vectors I calculated like Vector1 (lat2 - lat1; lon2 - lon2). Not sure this approach could be applied to Location coordinates.
Use location1.bearingTo(location2). But this doesn't give expected results. Seems like it gives "compass" results. Perhabs I could use it somehow but not sure.
Also tried few trigonometric formulas like here or here or here. They didn't give expected angle.
EDIT: Solution
The accepted answer works great. But to complete the answer I have to show that method of angleDifference. This one works for me:
public int getAngleDifference(int currentAngle){
int r = 0;
angleList.add(currentAngle);
if (angleList.size() == 4) {
int d = Math.abs(angleList.get(0) - angleList.get(3)) % 360;
r = d > 180 ? 360 - d : d;
angleList.clear();
}
return r;
}
I add points to list untill there're 4 of them and then calculate angle difference between 1st and 4th points for better results.
Hope it will help for someone!
vect1 = LatLon2 - LatLon1; // vector subtraction
vect2 = LatLon4 - LatLon3;
By definition of the dot product has the property:
vect1.vect2 = ||vect1||*||vect2||*Cos(theta)
Here's a breakdown of the notation
The term vect1.vect2 is the dot product of vect1 and vect2.
The general form of a dot product can be broken down component wise let v1 = <x1,y1> and v2=<x2,y2> for two arbitrary vectors v1 and v2 the dot product would be:
v1.v2 = x1*x2 + y1*y2
and the magnitude of some arbitrary vector v is:
||v|| = sqrt(v.v); which is a scalar.
The above is equivalent to the Euclidean distance formula with components x and y:
||v|| = sqrt(x^2 + y^2)
Getting the angle
Find a value for theta given the two vectors vect1 and vect2:
theta = Math.ArcCos(vect1.vect2/(||vect1||*||vect2||))
Approach 1 does not work as you described: Lat, Lon are not cartesian coordinates (One degree of longitude expressed in meters is not one degree of latitide, this is only valid at the equator). You would have first to transform to a (local) cartesian system.
An error is in the drawing: The angle marked with "?" is placed at the wrong side. You most probably want angle: 180 - ?
In your example the car ist turning less than 90°, altough your angle shows more than 90°.
To understand better make another drawing where the car turns left for only 10 degrees. In your drawing this would be 170°, which is wrong.
Approach 2) works better, but you need to sum up the angle differences.
You have to write yourself a method
double angleDifference(double angle1, double angle2);
This look easier than it is, although the code is only a few lines long.
Make sure that you have some test cases that tests the behaviour when crossing the 360° limit.
Example
(turn from bearing 10 to bearing 350), should either give 20 or -20, depending if you want that the method give sthe absolut evalue or the relative angle

how to set a tolerance to my event handler android

I'm trying to make a GPS Android app and am having trouble setting a destination point.
all the program does at the moment is grab your GPS location, and display your Latitude and Longitude, I want the app to tell you when you have reached a certain Latitude or Longitude but the coordinates don't stay at a steady number so I can never get the event to happen for more then a second before the coordinates change, I think I need the event to happen between two different coordinates, one being higher then the target coordinates and the other being lower but I can't figure out how to do that, someone please help
Specify a broader area that you'll accept.
if(lat > TARGET_LAT - 0.02 && lat < TARGET_LAT + 0.02 && lon > TARGET_LON - 0.02 && lon < TARGET_LON + 0.02){
// close enough!
}
See this for an idea on what the numbers should be.

want to show a image when enter a particular region of lat. long by zoom in and out android

hi friends i am able to display Google map in my android device and by default i am able to perform zoom in and out,so now i want to show a image when i enter,A REGION of between lat. long then a small pop msg appear at top of google map as "you enter buenos region"(Buenos is just place name whose coordinate area i take),so now how to show it in android,i have consult with iphone developer who develop same concept using the code below,but i am not understanding how to implement for zoomin and out for getting lat. long. of particular region..pls take a look below...
if((centerCoordinate.latitude < -34.538238) && (centerCoordinate.latitude > -34.672182))
{
if((centerCoordinate.longitude < -58.347702) && (centerCoordinate.longitude > -58.528976))
{
img_City.hidden = NO;
}
else
{
img_City.hidden = YES;
}
}
When you zoom, you need to get map the coordinates on the screen corners, you can do that by using
fromPixels()
Once you get this, all you have to do is check if the bounds like between the region bounds, like you did in the code in your question. The only difference is that instead of the center coordinates, you are using the rect formed by your screen as 4 coordinates.
If the bound checking works out, add an Overlay to the MapView.

Categories

Resources