Check if user is in the defined area - ios

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.

Related

Why does didUpdateLocation value differ from "my location" on map?

I'm getting a user's location over time and continuously overlaying this information on an MKMapView.
My problem is, the location isn't correct. Hear me out. MKMapView's blue dot for my current location is showing my location EXACTLY correct. Correct as could be. However, my location from didUpdateLocations is not this same location. It's showing up ~500 meters WNW. I'm storing locations as CLLocation and displaying them using their coordinate member.
I can walk around and it will show my path very precisely, but offset 500m WNW. Why is this happening? How do I get my current location without this offset?
Well, it seems that the problem is China's cartography. This is well-documented:
All Maps In China Are Wrong
What The Map?
A Solution (too complicated in my opinion)
...so.... what next?
I'm going to use Chinese map providers' APIs to provide a simpler solution (Autonavi, Baidu, etc)

Can I set custom location in CLLocationManager in iPhone

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

Polygon geofencing with iOS

I am trying to find a way to create several polygon geofences with iOS. I need to draw multiple zones in a city to represent areas, streets, etc. From what I've read so far, iOS only allows circular zone from a geolocated device.
Is it feasible with iOS?
Is there a web app somewhere to draw polygons on a map and generate the coordinates in an array?
1) iOS only allows to create circular geofences indeed however what you are trying to achieve is possible with some extra logic.
I have developed similar features so I suggest you to do the following:
create a circular geofence that embeds your polygon
when the device gets notified as being within the circular geofence,
start the GPS
every time you get a location update, check if its coordinates are
within the polygon
turn off the GPS as soon as the device's location is found within the
polygon, unless you need to be notified when exiting the polygon as
well
turn off the GPS when the device gets notified as outside the
circular geofence
As you need polygon geofences I guess you expect a good level of accuracy, so you would need to use an extra layer of GPS on top of the geofencing anyways, as geofencing is not accurate at all.
2) Have a look at those links:
https://github.com/thedilab/v3-polygon-shape-creator
https://github.com/tparkin/Google-Maps-Point-in-Polygon

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