How to notify user when he enters a specific type of place in flutter? - flutter

I want to build a flutter app in which I want to trigger a notification when a user enters a place of a specific type.
places of specific type means (saloon, restaurants, hospital, etc) these all are types of places.
Requirments
I want the system to work offline. (like if the user dosn't have
mobile data & user enters the specified type of place he should
recive a notification).
I want the system to work in background.
(when the app is terminated(killed) & user enters the specified type
of place he should recive a notification).
My approach
when the user installs the app and opens it for the first time, the
app will cal google places API and save latitude, longitude of all
places of specified type near him.
and then use the background_locator link plugin to monitor users
current latitude, longitude.
on every change of latitude, longitude find distance between users
latitude, longitude, and all places latitude, longitude that we
stored.
if the distance is below 50 meters between users current latitude,
longitude, and certain place latitude, longitude then trigger a
notification.
problems with my approach
Background service will be running all the time in background(also
when the app is killed) witch will consume battery alot.
As the background service will be running all the time the whole
distance calculation will happen every 5 to 10 secs or you can say
every the background service fetch users current location which is
also not a good thing.
If the user goes to any other city How will I update latitudes,
longiudes of the nearby places ?
As we know some places have areas(size) and some have small, and
distance of 50 meters will not be accurate for all places.
What I want from you
If you have a better approach for solving the above problem, share it
with me.
if you can improve the solution that is also appreciated.
do provide me names and links of plugins in your approach.

Related

How to get exact user sitting position latitude and longitude values in a room?

I want get exact user sitting position latitude and longitude values in a room or building. I am getting user location latitude and longitude values through CLLocationManager but not exactly showing. Is any possibility through get user exact building latitude and longitude values.
Thanks
Laxman
GPS precision is usually at best 10m, so you cannot expect to obtain positions with better precision than that, which is not usually enough for positioning within a building. Besides, if your user is not using GPS, you will get network-based positioning data which has yet lower precision.
I don't think you can use CLLocationManager or any other out-of-the-box positioning service for that.
Technologies exist that can be used to locate a phone within a building based on other sensor data (eg. https://en.situm.es/solutions.php), that perhaps you could apply.
There are also ways to improve GPS precision outdoors (eg. https://es.wikipedia.org/wiki/Wide_Area_Augmentation_System) depending on where you live. It all depends on your application.

store latitude and longitude in ios address book

Can latitude and longitude be added to a record in an iOS address book?
My app wants to display nearby contacts on a map. I know how to get the latitude/longitude from an address. I do not know how to save them so I can avoid repeated lookups
Yes, you can add a latitude-and-longitude address to a contact in your iOS address book. It takes one extra step to view the map pin from that address, but it works.
Open an existing or new Contact, and create a new address. Under Street, put in the latitude and longitude, with a comma between but no blank space.
Leave everything else empty: city, state, and so on. It will force you to pick a country, so either just leave the default, or if you want, you can select the country that corresponds to the coordinates, though it really doesn't matter.
For example, you could enter:
• Street: 48.8582,2.2945
• Country: France (or any country)
(For locations South of the equator or East of the Greenwich meridian, add a minus sign: e.g., -17.53655,-149.56832).
Save the address.
To go to the location in Apple maps, open the Contact and click the latitude/longitude address. This will take you to Apple maps. Don't wait for the map to come up, because if you wait the pin will be dead center in whatever country is listed. Instead, while it's thinking, just go to the address bar at the top and edit out the country so that only the lat/long is left and hit Search. This time, the pin will go directly to the correct latitude/longitude location. If you want Google maps, just copy/paste the lat/long into Google maps.
The example shown above should put you right at the Eiffel Tower. Bon voyage!
In iPhone native address book it's not possible to store. But you can do one thing, you can store info of the user in SQLite database in your app along with lat lon and if you want some synchronization functionality then you can create web-service which will update your SQLite database as per your logic.
Hope this will help you.
All the best !!!
I am not sure but this may be not possible to add latitude and longitude value to ABPeoplePickerNavigationController. but if you want to find distance between two Contact then you can find it from contacts's address or add your latitude and longitude value into database and use 2 option of mine .
There are two way for find location by address
1) How to get street address from ABPeoplePickerNavigationController
2) use reverseGeocodeLocation and also check this my answer CLLocationManager not getting City name this is helpful for you.

iOS Find Other Nearby Devices (GPS locations)

I have an app that allows a user to transmit their location to a server. What I am trying to do is have the user press a button that will send a push notification to anyone with the app within lets say a 3 mile radius. Can someone give me an overview of how I can accomplish this.
The only way I could think of doing this is publishing the gps coords to a server. Then when the user presses "Send notif" a message gets sent to the server, then the server does some complex proximity search based upon the location and then returns the values to the user.
My problem is, I have no server-side experience and have no idea how to program a GPS search algorithm on the server.
Is there a way for me to do what I want without having to write code on a server? I am able to use Parse to store the GPS coordinates. I'd like to keep my server code to simply storing and retrieving values and handle everything else client side.
Thoughts?
Each device should send their GPS coordinates to the server periodically. I think you already have this step. The next step is to find devices that are near each other. This is fairly simple.
Distance Between Two Latitude and Longitude Points
However, if you have millions of devices, it will be a problem of scale if you compare each update to all the other devices. You might bucket the devices to a certain area. For example, you might bucket the updates into 100 square mile areas. When an update comes in you need to only compare to those devies in that bucket plus adjacent buckets if they are near the edge. This is just top of the head analysis but hopefully it will point you in the right direction.
If you really want to put all the load on the client (iOS) side:
Query the server for IDs and locations of all possible recipients for the push notification
Store ID and Location in custom object and put those in a NSArray or a NSSet
Then
//otherUsers is the NSArray or NSSet with custom objects
//currentLocation is the users current location
for(MYCustomUser * otherUser in otherUsers) {
if([currentLocation distanceFromLocation:[otherUser location]] < 4829) { //4828 == 3 Miles in Meters, so 4829 is 3 Miles + one Meter
//send msg to server to perform push notf. to user
}
}
Done...
you should put this in a NSOperationQueue so that is can run in background an is not blocking the device
But as bbarnhart said... it's not very wise to put all this on a device.

How does apps like foursquare or gowalla implement their check-in feature?

If I had to build my own check-in feature from scratch, how would I go about it? I was thinking that once a location is determined using corelocations, I can add that location co-ordinate and timestamp to a database in some server. Now once one of my friends check-in close to that location, there can be a query to the database to figure out all check-ins around that location and around that timestamp. Is that how they implement this feature?
Those services use the current location (that you could get via CoreLocation or otherwise) in order to determine which venues to show near the user. Note that they usually have a database of business venues and the user selects the one they are actually and perform the checkin.
So, in order to figure out "who you are hanging out with", they only have to see who has checked in in that specific location, around that timestamp.
Note that the whole thing could have been implemented without location services and geographical coordinates - just choose from a list! Now, with location services, you can help the user search for the place quickly.

Core Location - fallback, location caching and alternatives

I have a few questions about Core Location.
1) Should the user refuse permission for my app to use core location, or core location is unavailable for some reason, is there a fallback? (Device Locale, for example?)
2)Can I cache a device's location for next time? Does Core Location do this itself?
3)I really need the sunset time in the user's area during the mid-spring season and I have a function to do that, once I have the Latitude and Longitude of the device. Perhaps I can just make an assumption about the time based on Locale? (Example: In the US, assume approximately 7:00pm.)
EDIT:
I really am trying to calculate sunset in the users area for an app. Nothing to do with the map. I am considering the following sequence of events:
Check for Core Location availability. If yes, use it and store it in NSUserPreferences. If Core Location is unavailable, go on to the fallbacks.
Check for a stored Location. If it's stored, use it. If not, go on...
Check for the user's chosen time.
1) Strictly speaking, if the user does not allow using CoreLocation or, if permission were given but CoreLocation is not available, there is no other fallback to get the user's location as a latitude, longitude pair. Using the locale may not work in all of the cases. First, it will just give you an approximation which may be way too far from reality. However, it's up to you to judge whether this approximation is ok for your app. Moreover, there are some users using a locale different from the one related to their country. And, you have no guarantee that people travelling abroad will adjust the date/time every time.
2) Core Location caches by default the last location retrieved from the GPS unit. However, for people travelling abroad this cached location will be certainly wrong (even for people travelling just a few miles away), and in general, you should discard the cached value and localize again the user each time. I understand that for people travelling within their country this will not (usually) create huge problems. But it just depends on the country: travelling within Italy will not change the time, but travelling across the US may change the time up to 3 hours.
3) I would suggest to try using Core Location and, in case of problems, simply ask the user to input his/her local time or location (the city should be enough for your purpose). If you choose to ask for the user's location, then you can get the corresponding latitude/longitude pair but this will require a working network connection.
2) From the online docs for CLLocationManager:
The location service returns an initial location as quickly as possible, returning cached information when available.
You can check the CLLocation timestamp to see if it is a cached value or not.
3) If you do decide to use locale for an initial TZ approximation, remember that users travel, and may not reset their locale promptly. You can get the current TZ object with:
[NSTimeZone localTimeZone]