Can I set custom location in CLLocationManager in iPhone - ios

I am working on a compass app showing true heading (i.e directs towards true north) which uses location as described by apple documentation
IMPORTANT
This property contains a valid value only if location updates are also enabled for the corresponding location manager object. Because the position of true north is different from the position of magnetic north on the Earth’s surface, Core Location needs the current location of the device to compute the value of this property.
what i want to do is that if the user's device is not connected to internet or the user denies permission to access its location then I take coordinates manually from user and give these coordinates to CoreLocation for a correct true heading. is this possible?
Thanks in advance!

What you are asking for isn't possible using CoreLocation directly. With LocationManager, if you want true north, you must call 'startUpdatingLocation` so that headings can be returned with true north values. There isn't a method to set the location manually for LocationManager to use.
However you can calculate true north based on the magnetic value returned. You could have the user set their general location manually, as part of the setup, and store it for use when calculating true north. You could use a basic lookup table with locations and magnetic declination values. Kind of like a real map and compass would use. However, magnetic declination values change over time so you would need a way to update it.
If you are not familiar with magnetic declination, here is a pretty good link from REI That should give you the basic concept.
These links provide more details on how to calculate magnetic declination:
NOAA - http://www.ngdc.noaa.gov/geomag/WMM/
iOS - https://github.com/stephent/ObjectiveWMM
lookup Table - http://www.societyofrobots.com/robotforum/index.php?topic=11855.0

Related

How can I get the current pitch, yaw and roll of the iPhone in Swift?

I'm looking to get the exact current pitch, yaw and roll of an iPhone device, relative to a base position. A lot like what is done in the Compass App. Most of what I have found online is about detecting changes in the result, while I am looking for an absolute position relative to a base position, the base position (pitch: 0, roll: 0, yaw: 0) being this position:
Can anybody suggest what I should do to get this? I need this one-off, basically as a result from function call.
The device does not track the orientation constantly. Your app needs to indicate it needs this data (through the Info.plist file) and start monitoring it before you can access it.
The information is accessible though the deviceMotion property of the CMMotionManager class. It is an optional, indicating that it is nil if the device doesn't support this or if you didn't start monitoring the data beforehand.
You need to specify a reference frame that you can use for this purpose to startDeviceMotionUpdates(using:) so that you get proper values. What you want is probably .xTrueNorthZVertical. Note that the documentation for this states that:
Note that using this reference frame may require device movement to calibrate the magnetometer. It also requires the location to be available in order to calculate the difference between magnetic and true north.
This probably means that you can't just read it spontaneously. You will probably need to start monitoring when your app starts or the user enters the view where you need it, and check the value later when the calibration is done and the user does something to need it.

Get current location without using GPS, Wifi and cell tower

Is there any way to get current location without using GPS, Wifi and cell tower.
You can derive the lattitude roughly and with big errors, if you analyse the magnetic field, especially if you can ask the user to place the phone on a flat surface, even better if you can ask him or her to have it point north (but that might prove unreliable).
Subsequently ask the user to point the phone to the sun. Use that information to derive the longitude, given that you know time and time zone the phone is set to.

Check if user is in the defined area

In my app I want to check if my position is within defined area. I know the area coordinates and I want to check it when app is launched. How can I do it? As far as I know, geofencing can help me, but this technique always scans user's location. And I need only a manual check.
If you've got the users coordinates from a manual check with CLLocationManager then store them as a CLLocation object, then have another CLLocation object that contains the centre point of the region you want to check. You can then use [someUserLocationObject distanceFromLocation:centralPointOfArea] which will give you the distance the user is (in metres) from the central point, and you can make a determination from there.

How to find the inverse of the China transform in MKMapView?

It seems to be a known fact that MKMapView (and Google's maps in general) have a varying offset on 100-600m which makes annotations display incorrectly on the map.
According to this thread, Google has a private method called _applyChinaLocationShift, and it works, but apparently only for CLLocations that are given by CLLocationManager. For arbitrary CLLocations, it returns nil. The app I'm writing only needs to work in one city, so I've thought of pre-sampling the area using _applyChinaLocationShift and store the inverse transforms in the shipped app if that was possible.
So basically, is there any way to convert a coordinate to a coordinate that corresponds to the transformed China maps?
How about using location simulation in the Simulator and feeding it a bunch of coordinates in that particular city.

iOS Dev: Map Offset in China

I made a very simple APP in which I can throw a pin right onto the location I am standing at (just a beginner's practice). But I found a problem.
I swear neither I was moving nor the device thought I was moving. And I directly use the geolocation to set the pin. but the pin and the current-location blue point are hundreds of meters apart.
(By the way, the blue point expressed my real location at the time.)
This is a famous problem of Google Map on iOS in China. Put aside the complicated issue of the so-called national security, where I want help is what should we do as a developer. Technically, is there a way, in programming, to figure out what exactly the offset is and correct it?
Does anyone have any idea?
At what time did you place the pin? iOS has up to three sources of location data (cell tower triangulation, Wifi sniffing and GPS) and will keep you up to date with the most accurate. So often you get a not very accurate location, then a more accurate location, then an even more accurate location.
If you have a MKMapView open then something you can do is key-value observe on its userLocation property rather than starting any sort of CLLocationManager. That way you'll always be updated with whatever the map view has decided is the current location, meaning that you don't need to try to match your logic to its.
I did some research on the offset, but haven't gotten a satisfying result yet. The added offset is deterministic, i.e. given a location, the deviated location is fixed. So my goal is to get the deviation function, f(p)=p', where both p and p' are 2D points. You can check here if you are interested.

Resources