I'm making an iOS app where users are able to place a pin (CLLocation) on a map and all other users within x miles of that point will be able to see it on a map. How can I do this?
1) User places a pin on the map -> pin placing function sends a message to a server with latitude, longitude, and the annotation name.
2) Server checks what users are within the radius -> Sends silent notification to users.
3) Local apps drop a pin.
OR
2) Server sends a silent notification to all users (containing the latitude, longitude).
3) Local instances of app decide whether or not to drop a pin on the location.
Basically you have a fair bit of choice here - should users need to constantly update servers with their location, and only the relevant users get sent a notification? Or do you want all users to receive a notification and the app to decide if a notification should be dropped.
A simplistic view of one possible solution could have three major components:
The client-side app which allows users to view and place pins.
A server-side app which receives locations from and sends pins to many clients.
A database which stores all of the known pins.
The question then suggests two sequences of interest:
Creating a pin:
A user creates a pin on a client app. The client app sends a description of that pin to the server (this is often an HTTP POST request but there are many options).
The server receives this request, validates that it understands the description of the pin and that the client has permission to create it, converts it into a format convenient for storage in a database and sends it to the database.
The database adds the new pin information to its list of known pins.
The server responds to the client's request with a "success" message confirming that the pin was saved.
Viewing pins:
A client app needs to show nearby pins (because a user launched the app, or switched to a map view, or the app received a notification, or whatever). The client sends a request to the server asking which asks for all visible pins and which includes the client's location. (You can decide if the client also get's to define what distance counts as "nearby" or not.) (If creating a pin used an HTTP POST then this is probably a HTTP GET but again there are many options.)
The server receives this request, determines if it should share pin information with this user, and if so constructs a query which will obtain all "nearby" pins from the database.
The database responds to this query with information about 0 to many pins.
The server converts the database representation of these pins into a format the client app can understand and sends a response containing these pins. (As the set of pins becomes very large this may become more complicated; the server might only return some of the nearby pins and information about how many more were not included, the client could then get another "page" of results in a second request.)
There are many decisions to make along the way and many tools to choose from to build all of these pieces. There are many programming languages you could use to write the server-side component (and many frameworks written in those languages which try to make building certain types of web applications easier). There are many data formats you might use to exchange information and many databases you might use to store these data (some of which have built in support for the sort of geolocation math you would need to determine which pins are "near" a given latitude and longitude).
Related
Is it possible to share user's location to other user (of the same app)? I want to build a geolocation sharing app that pings/notifies user A once user B has crossed a certain radius. Doable with firebase or a similar third party? thank you in advance
Let me see if I understand, what you want to do is:
1 - If user A passes near user B (on the street), notify both users that they are nearby?
2 - Do you want to share the user's location through an application and send it to another user, either through a social network or email?
If it is option 1, you will have to obtain the latitude, longitude and accuracy of the users and keep sending and obtaining it from Firebase every so often (or through a socket connection like socket.io) and make a match and calculate the radius or distance between both points.
Please suggest the most efficient approach to implement different users tracking each other on the map, so every user can see others current location and they can see his.
For example: if one user moves, other immediately see his new location and vice versa. If the user moves and new users appear in his vicinity, they are tracked.
I would like to use Parse as a backend for this.
I tried the approach of saving new location on didUpdateUserLocationand then running a query in background, configured as myQuery.whereKey("location", nearGeoPoint: currentGeoPoint, withinKilometers: 0.5)
It works but apparently uses lots of bandwidth, as even a small change in user location triggers a query to Parse (and i see internet activity indicator on iPhone status bar working all the time).
So i have a feeling that it can be way more efficient.
Should i use push notifications instead?
If so, what would be the implementation in general?
Thanks a lot!
If you want to monitor location changes in realtime, then this will of course require a substantial amount of interaction with the remote server. While Parse may or may not be a good backend for this task, you should keep in mind that, if you are using the free plan, you have a limit of 30 API requests/second (and this may easily be exceeded in this scenario when you have multiple users).
Limiting the updates to significant location changes may be a reasonable compromise, as described in the documentation. Here, you would get a new location when the user moved ~500m, but this could of course be the downside when you want to literally follow the user in person.
Using push notifications to inform other users of a user's location changes might be more efficient:
send a push notification to the followers once a user changes
her/his location. This would mean one request for each location
change.
update other users' location changes when your own
location changes. Here you would have two requests for each location
change.
Using 1, you would still get updates from other users, even when you are not on the move. Note that these requests are counted for the device, not for Parse. I.e. Parse includes sending push notifications in the request limit.
I'm looking into MAP profile (on iOS) because is under standard profiles and you don't need MFi to use it.
My question: is it possible to use MAP profile to transfer data (in messages)? or are you restricted to just messages, calls and emails? In other words - when I send data to phone over MAP profile is data accepted by any application or specifically my messages application (or phone application, or email application).
I hope I was clear :) thx
My own replay for purposes of "closing" the question.
I couldn't find the way of sending data over MAP - at least on iOS and event if I would manage to send it I'm almost certain that only specific application would be able to accept the data. So for example mail would be accepted by Mail application.
As I understand for the moment, the location and time sensitive passes in Passbook only support time and/or location based notifications. So at the correct time and location, the user will get a notification for the pass.
I was wondering if these properties also can be used to change the pass. For example, if you are in some specific store, the coupon provides a 50% reduction instead of a 20% reduction. If it is not possible to do this locally on the iOS device, is it possible to send a request to the server based on location and/or date to achieve the same thing?
Sorry to be the bearer of bad news, but it's not possible to accomplish this.
Firstly, the data within the pass is fixed at any point in time. As you've said, it can be fixed to a list of locations and/or a date.
Secondly, the pass cannot communicate with a server except to request an update in response to a push notification. This means you will never know where a pass is.
The only option way to achieve something like this would be to generate passes using an app that is location aware, but I don't think this is what you're after.
You can send a push update to a Pass at a specific time. This way you can (for example) convert a 10%-off coupon to 20%-off on Fridays (and then switch it back after Friday).
After a user has initially 'Added' your Pass promotion into their Passbook you can update it at any time without requiring the user to 're-approve' your update.
Your server does not know when a Passbook user has triggered a location alert - otherwise you could track their movements via Passbook. Apple does not want their customer's security to be compromised in this way.
However, you could issue a coupon that is normally 20%-off (for most stores, or online) but that the location alert for a specific store said 'Get 50% Off at this store'. When the customer comes in to have their Pass scanned & activated, your server will then know the customer's location and can apply the 50% reduction.
I'm developing a chat application, and a requirement is to get the device details for users within some distance (i.e., devices within 100 miles who are using same application). I want to get the details and they should be shown in a UITableView.
There are far too many pieces involved in this for a single answer to include all the code, however I can give you a high-level overview:
You'll need to send the device's current location (found with CLLocationManager) and an identifier to a remote server on applicationDidBecomeActive: and whenever you determine that the user has moved a significant distance.
Your remote server stores these coordinates, the identifier, and a timestamp into a database table and periodically prunes old entries.
When you load the "Nearby Users" screen your devices makes a request with its own location to the server, which returns the list of users within 100 miles. The Haversine formula is the proper way to calculate distances between GPS coordinates. Once you have the results, you can show them in a UITableView.
When the user selects a nearby user, you can use the identifier it sent in step 1 to start brokering a connection between them. This part is highly dependent on your specific chat system.