How to find if you're facing a certain location in Android? - android

I've searched online but haven't yet found anything like this. Basically, is there a way where I can know if I'm facing a certain location.
For example, I have my current location in latitude & longitude and I have a second location in latitude & longitude. Now I want to know when the second location is directly in front of me as I turn.

I'm going to assume that you mean the phone is "facing" the location of interest, and you already know which axis will determine this. What I would do is use the SensorManager.getOrientation(float\[\], float\[\]) to get the radians of where you device is facing, then convert it into degrees.
Next, I would ensure I get an accurate and current point from the device (GPS, not Network), and call Location.bearingTo(Location) on the location from the device with the destination location as the parameter to get the degrees to it.
Finally, I would compare the two results and determine if the device is "facing", within a certain range. This might have to be adjusted based on how far the destination is from the current location, but I would experiment with this a bit.

You can predict your direction/location if you use Android location Manager. Take a look at this example

I don't know if this help, but you could take a look at the Places API from Google: https://developers.google.com/maps/documentation/javascript/places#place_search_responses
The response has an attribute called viewport that with some processing can help you

Related

Android: Get current location instead of last known

EDIT: As Francky Vincent said, I see that price depending on distance is not advisable. I have 4 parts but only 3 are the prices depending heavily on the distance (and planning to change it later). But, I still need to get current location as I have 'x.x KM from you'.
A little bit of intro:
When I was around somewhere with low coverage, I open the Grab app and able to get my current location, even though will take too much time. My own app have no problem with location but at the same location, it will get the last known location - and I don't want that since one of my app feature is the price is according to the distance between current location and target.
For the codes, I just using the examples provided for Fused Location by Google in Github and seems like it's not enough? My aim is to get current location instead of last known - just like the Grab app.
Is that possible using Fused Location? Or did the example provided can achieve what I want but I missed something important?
I referred to this question but still got clueless. Really new with this feature.
The strategies that I can come up is:
Start app
Check permission
Request permission
Get current location
Save the latitude and longitude in SharedPreference
Stop getting location
Please help. Thank you!

Android - how I can I achieve location accuracy in Google Map

I am self learning Android programming at the moment. I was about to write app that will display my location on map without using GPS.
I have tried using NETWORK_PROVIDER and found that my accuracy is constantly at 2000 even in city area with a lot of wifi around the area.
I would like to know how could other map application (e.g. GoogleMap) is able to achieve high accuracy without using GPS.
They use GPS. Or they lie about their accuracy. Ever seen the big blue circle around your position in Google Maps? That means they think you're somewhere in that circle, and are guessing about actual position.
The only way to get accuracy is to use GPS/GLONASS signals. A-GPS can help to fix position quickly because it provides info about which satellites are in view from your phone cell position (your device don't spend time trying to get signals from satellites not in view).
The 'High accuracy' mode is just a lie from Google to know your position all the time to monetize you in perverse ways
If you are using the network provider to fetch the location they are not very accurate. SO its not a good idea to fetch the accuracy of your position using
network provider. Its best to use GPS to get the location updates. You can use GetAccuracy() method of Location class and see for the value it returns.
Let Say if getAccuracy() retruns 25 then you can leave this value wait for another gps value which is more accurate.

Geo Fencing in Android

I am trying to build geo fencing in my android application. however i am not clear with this idea. whenever user opens my app, i want to see if he is in any AMC theater. how do i do that? should i use latitude longitude values or i should use physical address? if i use lat lon values how accurate will the output be? if i go for physical address, how time efficient will it be?
i have currently written a code wherein i have hardcoded the values. but thats not going to work for real app. my app can track users coordinates but i am not clear how this data can b put to use.
You need to use latitude and longitude, with very less accuracy (may be 20meters or less), and just look for Satellite GPS coordinates. If the device gets a satellite GPS fix, it would have very good accuracy (sometimes as close as 5m), and based on that, do whatever task you want to perform.
Best bet is to get the lat/lon coordinates of nearby AMC Theaters from the Google Places API. Calculate the distance to any of the points and use a threshold to determine if you're in the general vicinity of the building. The geolocation point is bound to be on the edge of the building, not the center of it (or perhaps even on the street), so it's unlikely you can just use a simple radius from the point.
For geo fencing, the best bet is to scan for the WiFi networks in the area and if any match the properties of your desired location, then you're in it. Of course, good luck getting that data. The other thing you could do to ensure users are in the venue is to plant NFC tags in the building and have them scan the tags. Again, this may only be feasible if you're doing a contract for AMC. QR codes are too easy to duplicate. Anyone could take a picture of one and scan it at any time.

how to get the most accurate location using GPS and AGPS with given time in android?

I have a below requirement.
Find location of user from GPS and AGPS. (we are going to use Samsung Galaxy ACE mobile phone)
Note: For every transaction first location will be the reference location for the next activities.
Below are the constraint which has to be considered while solving this problem.
user should be within 10meter range of the reference location. meaning (Reference location - current location) <= 10meter (distance calculation by Locaiton class API).
Location has to found in the given period of time.
let say 20-25sec for finding each locaiton. the time can be extended to max 35sec.
My user is always be outside of the Shop while taking the reference location and then inside for all the other activities.
What I am doing
find the reference location with accuracy of 30m with 25sec of time. store this in static variable.
find the location for next actiivty and calculate the difference. if difference >=10m tell user to perform that activity again.
My Queries
Is this possible with such fine accuracy in the distance with given Time and place?
How google calculate this distance?
Does google finds the location with such accuracy? or what is the accuracy of Google Map using GPS? for e.g. at given particular time and location given by the Google MAP by GPS how much it is accurate? like if i am standing near to my BANK then what is difference between co-ordinates on the google map on the server and the co-ordinate given by google map through GPS on mobile phone.
I have did enough experiment on this problem and finally came here for help.
i did the observation by doing variation in timing, place, accuracy. still need to find one final solution. as we have to answer the client whether it is possible or not?
The GPS can provide most accurate match but only outdoors. It is possible to achieve such accuracy but not guaranteed.
There are formulates for finding distance between two points on a sphere. However, for rough approximations euclidean distance can be tried.
The location and its accuracy depends on client side GPS. Google just reads it.

Android : Getting CURRENT coordinates (not lastKnownLocation)

Right now, I only know of one method to do this:
- Get last known location
- Have the location manager request location updates
However, I really only need to get the CURRENT coordinates ONCE right when the application is called, but it's not doing what I want.
What's the simplest way to get the current coordinates? Is there something I could call or some code I could use just to get the location RIGHT NOW ?
thanks in advance! I'm still a little new with android development.
What's the simplest way to get the current coordinates?
There is no way to get the current coordinates on demand.
Is there something I could call or some code I could use just to get the location RIGHT NOW ?
No, for three related reasons:
Not all location technologies are low power. GPS, for example, is a serious battery hog. Hence, GPS is not powered on unless something is actively seeking a GPS fix.
Not all location technologies are instantaneous. GPS, for example, takes some number of seconds to get a fix after being powered on.
No location technology is universally available. GPS, for example, may be unavailable because you are in a large building.

Categories

Resources