Compare Location coordinates on Android - android

We want our application to get location data when user opens the Activity and check if it's inside a certain boundary of location.
We are able to get the Coordinates of the current phone location now we want to compare it that if it is inside a building location or not. How do we check if the coordinates (lat Long) of the phone is inside a specific radius range?
thanks

You can use google's Geofence API.
new Geofence.Builder().setCircularRegion(latitude,longitude,radius);
https://developer.android.com/training/location/geofencing.html

Related

LastKnownLocation is reset everytime

I would have thought that requesting the "lastKnownLocation" would return a saved coordinate (GeoPoint) that points to the last known location of the device (from when it last had access to the GPS functionalities).
According to some tests (made on OSMDroid's GpsMyLocationProvider), it seems like requesting that location returns a NullPointer.
GpsMyLocationProvider provider = new GpsMyLocationProvider(MainActivity.mainActivity);
provider.addLocationSource(LocationManager.NETWORK_PROVIDER);
locationOverlay = new MyLocationNewOverlay(provider, map);
I've been trying to set up default GeoPoint for centering the map when it is first launched, and then recentering the map where the GPS now has confirmed a position.
The problem is that provider.getLastKnownLocation() returns a NullPointer exception unless it is given time to actually get the current location from the GPS.
What am I getting wrong here? Shouldn't the "last known location" be a GeoPoint that is saved in memory on the phone and always have something there, unless the phone never ever had access to GPS localization ?
Please see https://developer.android.com/training/location/retrieve-current
You must set the permissions correctly too. Note that at the bottom they describe why the location may be null so see these for troubleshooting.
If you're using an emulator see How to emulate GPS location in the Android Emulator?

Notification regarding your location in Android app

I want to create an android app which asks user for a location input and runs in the background. Whenever user is within 1km radius of the location the app will display a notification “Within 1 km of xyz location”..
If nor the same,can anyone suggest me similar solution.
Thank you.
Step : 1 Firstly get latitude and longitude
this Url help you.
How can I find the latitude and longitude from address?
Step :2 Save the latitude and longitude
Step :3 By the onLocationChanged method you can get the required distance, after that you can generate notification.
May be this help you.

Tracking the location in android

I got the current location latitude and longitude while giving on in a switch button in android and displaying the location in google map. But I need the latitude and longitude changes automatically wherever the device moves and the location on the map should change with respect to the position. How is it possible? Can anyone give me a way?
You could have a look at GoogleApiClient.
You can use requestLocationUpdates(...) to get the users position in a given intervall.
You can find more Info here
But honestly you could have find the answer on your own if you googled a bit.

How to show notification when hitting a specific latitude and longitude on Google Maps v2

I was able to create a map fragment already. I wonder If I can make my app have the ability to detect if you're within around uhmm, 200 meters of a certain landmark ( lat = 14.650778, long = 121.048117). I wonder if detecting if you are near a landmark is possible and how to implement it by showing a notification. Thanks!
You can do this with the GeoFencing functions of Play Services.
https://developer.android.com/training/location/geofencing.html
Create the notifications with this
http://developer.android.com/guide/topics/ui/notifiers/notifications.html#CreateNotification
You can use the the distanceBetween or distanceTo methods of the Location object to find out what is the distance between you desired point and your current position/ clicked location on the map.
and depending on the output, create a notification, you can use this tutorial for notifications:
Notification Tutorial

Android : Get notification when user enter in specific location

I am developing android application which gives notification when user enter in specific location
User can specify the location by using latitude longitude(ie Google Map)
I know how to get latitude & longitude but my problem is that when user enter in specific location then it will not exactly match with previously specified latitude & longitude.
As shown in image suppose user specify the location called "My Place" when user enter in area (about 20 meter) then application should send notification to user.
I want know how I can compare the latitude & longitude which user specified(My place) and current latitude & longitude which application fetch by GPS.
The comparison made in such way that it will true if user near by of My place in area of 20 meter.
(This 20 meters is approximate.)
Can I set accuracy of in android e.g. 20 meters.
Thank you.
The best approach to this problem is using the GeoFences feature. Please refer to https://developer.android.com/training/location/geofencing.html for more details.
Outline:
- The application registers with the underlying OS - saying - here is MY list of geofences (specific location + radius from the location) that I want you to monitor.
- If my user comes within this geo fence - wake me up and tell me so.
- At that point of time - you can go ahead and perform any step (either call a server and ask what information you need to display to the user) or just send a push notification (in app notification) to do the necessary work.
Hope this helps.
Look at the LocationManager.addProximityAlert function. It does pretty much exactly what you want. Warning, it does use a good amount of battery.
You can make gps pooling calculating with spatial distance functions
There is point sdk (android & ios) from Bluedotinnovation which has more accuracy and less battery drain also similar free sdk from Radar
Radar geofencing is more powerful than native iOS or Android geofencing, with cross-platform support for unlimited geofences, polygon geofences, stop detection, and accuracy down to 30 meters.
Also they have ReactNative support.

Categories

Resources