iOS NearBy devices - ios

Hi I am creating two apps where each app needs to know the location of the other app. I am using corelocation for that. However I am not sure whats the best/efficient way of getting the nearby devices. I can create a database with co-ordinates using parsi api. However I think that would be a lot of work to calculate the shortest distance every few minutes. Any ideas? I have a map for each app and i want to display the shortest distance between the two users on the map.I am using google maps api for ios

The API to calculate distance is pretty lightweight. Internally you use the Haversine formula to calculate distance including the curvature of the Earth. From the iOS perspective though you simply do this:
CLLocation* previousPoint = [self.allLocations objectAtIndex:i-1];
CLLocation* currentPoint = [self.allLocations objectAtIndex:i];
CLLocationDistance distanceFromPrevPoint = [previousPoint distanceFromLocation:currentPoint];
You can easily iterate over the other devices in the zone. If you want to reduce the number of calculations, you could only calculate distances to devices in the same base latitude longitude (ignore minutes and seconds).

Since you're using Parse, you should be able to do a PFQuery for all place objects within a given range. See the documentation here: https://www.parse.com/docs/ios_guide#geo/iOS (Geo Queries)

If they're close enough (~30 meters) you can use iBeacons.
What would work the best depends on your particular app's needs.
Edit: Since you said your distance is too far, iBeacons won't work.
The brute-force way to do this is to run through all connected devices and calculate the (Pythagorean) distance to each one, and select the ones that are within your distance threshold. That's very time-consuming however.
Instead you might want to have each device report some sort of region code for each location (State? County? Zip code?) as the location changes. You'd use geocoding to generate the region information. You could have the reporting devices do the geocoding themselves, so they are only responsible for updating location information for a single device and you don't bog down doing geocoding. You'd report lat/long and region information to the server as it changes, with a "choke" to only report changes on significant changes, or once per minute, whichever is LESS frequent. (I remember reading in the docs that you are only supposed to submit a small number of geocoding calls or you get locked out and/or your app gets rejected.)
You'd collect the data in a central server.
Then you could start by requesting other users that match your current region (and possibly nearby regions) and then do distance calculations only on that small subset of your data that matches the region code.

Related

Why i am getting different locations name while i am at my home?

I am developing an iOS application to track user movement of the different location. I am using GPS to pull the user location[Alway from the setting location]. it works perfectly, but I am getting different location name while i am in my home.
Like in 1st bedroom you are 1503 location
and in 2nd bedroom, you are at 1702 location
how these different locations update works in background process?
It all depends of the service you are using with CoreLocation. You have here a list of the different services provided. The Standard location service (tutorial here) will be the most accurate and customizable but the less power friendly. CoreLocation often get you a location then update it to get you more and more precise location, the accuracy will also depends on the quality of your network.
You can customize the Standard location service with the following lines :
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters
locationManager.distanceFilter = 100.0 // In meters.
The desiredAccuracy is important.
But have you ever notice this?
When you're in a building and have WiFi turned on then CoreLocation uses WiFi to also pinpoint where you are.
How does identifying a location using WiFi work?
It's roughly something like this:
Imagine you that your building has 2 sides. Left side (1502) and right side (1702).
The left side has a wifi network named LeftSideOfBuildingWiFi
The right side has a wifi network name RightSideOfBuildingWiFi
At every moment your locationServices is turned on...Apple will capture the list of WiFi networks. It will say at 1502 the LeftSideOfBuildingWiFi has a stronger signal.
So now some other person enters the house and is connected to LeftSideOfBuildingWiFi or has stronger signal with that...Apple will conclude that you're likely at 1502.
This helps preserving the battery of the iOS device. WiFi consumes far less energy than the GPS chip itself.
The same is true if you're in the downtown. Yet if you're in the middle of nowhere in the road then it doesn't apply.
The same concept works for significant location services. They use cell-towers rather than GPS chip. Say there are 4 towers near to you and each one has a different signal strength. Likely you're closer to the one which has a stronger signal...
There is a lot of error in GPS readings. They get much less accurate when indoors, and can be off by 1000+ meters. Given that much error, it is not at all surprising that the location might geocode to different addresses when you are in different parts of a house.

Reading parameters from DJI drone

I have to make an iOS application for DJI family of drones, in Swift.
I went to the official web page, successfully integrated the SDK via CocoaPods, but I do have couple of questions:
How to get the current altitude of the aircraft?
How to get the current distance?
How to get the current speed?
Is there any way to read the internal memory size of the aircraft and what's the remaining space?
I've also managed to get the GPS signal via DJIFlightControllerState
Here's the link to the method for Altitude
To get the distance between the aircraft and some other point (ie the RC or Homepoint) you will need to get the Latitude and Longitude of all the points and use your own logic to calculate the distance from each. You can check out the Android Location class to accomplish this. Or you can use a widget in our UXSDK: DUXDistanceRCWidget
or the DUXDistanceHomeWidget
To get the speed of the aircraft is a similar concept - you can use our method getVelocity under FlightControllerState class for X,Y,Z and calculate the speed. Or again, we have a velocity widget in our UXSDK
To get memory size of your SD card you can look at the class mediaFile however information on the memory of the drone itself is not made available.

Getting which contacts are close to my current location?

I'm experimenting with an app for my own use, and trying to find an energy efficient way to get the Contacts whose addresses are close to my current location.
There are about 100 people in my Contacts list each located in another town, maybe 5-60 km apart. Essentially after I've visited about 5-6 of them I'm running out of time and I just want the next two or three to be really close to my location.
What I'm doing now, requesting directions by selecting a Contact manually and seeing how much time it would take to get there, which is fine... But as the client list grows I have trouble remembering which ones are close and I keep selecting them and never get it right.
I tried storing them in an NSDictionary and grouping them by locality but it would be great to have a simple radar like report where the program would "see" which points are close just as one is able to figure out immediately by looking at a map whith 20 placemarks.
Any suggestions?
How does -distanceToLocation: (iOS Developer Library) sound to you?
From the comments I understand that you have the locations of all contacts. So you just need to loop through the contacts, get the distance to your current location and compare them...
You could possibly make an array or dictionary of CLLocation and CLLocationDistance objects and sort them by the distance.

Finding current region with lat long in offline mode

I am currently working on an app which requires the current region in which the user is in.The worst part is app is completely off line.
My logic :
1.Take a screen shot of the city draw squares on that.
Store square 4 points (lat long values taken with respect to map) in DB.
With the lat long values got from gps i can easily find out lat lont belongs to what reason.
I am just wondering if anybody can suggest me better idea to work my app offline.
Thank you in advance ..
You will probably find you have problems getting a location if you have no network access. iOS uses assisted-GPS, which allows the device to both lock onto GPS satellites much faster than it might otherwise take, and also pull in other data from the network to quickly determine location.
Without network access you may not get a location reported back at all, especially if the app was being used indoors (vanilla GPS reception is typically very bad without line of sight). If you do get a location it may take several minutes for an accurate enough reading to be provided.
you can use the RouteMe library which is based on OpenStreetMap. this allows to download map data in advance.
If you want to work with screenshots (from a legal source) then you use the Helmert transformation to transform between gps and picture-pixel coordinazes.
you need at least 3 points in the picture-map for which you now the lat,lon coordinates.

getting the location and speed via mobile platforms

Is there any possibility of getting the location of a user, moving direction, and the speed via mobile platforms(client side programming like j2me) ? if there is availability in any platform please let me know the platform and please give me some study links to study about it?
regards,
Rangana
I'm not sure if there is an API for this, mainly because I don't think that this information (velocity) is available.
You can still figure it out though, and this would work on all cell phones that allow you to access their "current location".
Ping the phone for it's current location every n seconds (10,20,30 seconds, etc...)
Log the location of the phone at every ping (lat,long)
Determine the distance traveled from ping-to-ping. You may need to use vector resolution (http://www.physicsclassroom.com/class/vectors/u3l1e.cfm)
For example, if a phone moves 1000 meters over the course of a 30 second ping, that means:
1000 meters / 30 seconds = 33.333 m/s
Doing this, you can also determine acceleration, etc... This would not give you instantaneous velocity or acceleration, but instead average velocity and average acceleration.
Without GPS it is impossible to get the speed and exact location. You can however retrieve the base station location from several web services and determine your approximate location.

Resources