Giving the different distance between two points using wifi and 3G - ios

I am calculating the distance between two locations like below
CLLocation *locA = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
CLLocationCoordinate2D coordinate = [self getLocation];
CLLocation *locB = [[CLLocation alloc] initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
CLLocationDistance distance = [locA distanceFromLocation:locB];
CLLocationDistance kilometers = distance / 1000.0;
But it giving the different result when i connect to wifi and 3G network.how to get the same result for both.

You invariably will not get the same location for both. In fact, if you come back to the exact same location tomorrow and turn on location services, you might not get the same latitude and longitude even if you stayed with the same technology.
The latitude and longitude you receive from a CLLocationManager is not an exact science. In fact, if you look at the original CLLocation objects you received, you'll notice that there is a horizontalAccuracy property that reflects how accurate/inaccurate the coordinate could be. When you first start location services, you'll even see multiple locations come in, generally with increasing accuracy.
But it will never be perfect and you shouldn't expect it to be. This is one of the reasons why it's important to test location-aware code on a real device, because the simulator will lull one into a false sense of absolute accuracy which doesn't exist in the real world. You should write code that anticipates this. And, if nothing else, you should start considering horizontalAccuracy of the objects you receive from the location manager.

there's nothing wrong in the code lines you posted,
the only line that could give you differences in the 2 cases (wifi and 3g) is your method [self getLocation]
where i guess you get the device location.
In this case your device may use both gps and wifi access to calculate its location, so little differences may occurs (you may have noticed that some map applications advice you to turn your wifi on to get more accuracy)
Anyway,
in your getLocation method try to add a more precise accuracy when you use
CLLocationManager
i tried this:
- (CLLocationCoordinate2D )getLocation {
self.locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
CLLocationCoordinate2D startCoord = CLLocationCoordinate2DMake(locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude);
return startCoord;
}
and the accuracy is enough to get no differences between 3G/wifi
but you could set it to
kCLLocationAccuracyBestForNavigation;
kCLLocationAccuracyBest;
kCLLocationAccuracyNearestTenMeters;
ps
i hope you are using a device with GPS, of course...

Related

CLLocationManager sometimes provides wrong coordinates on iOS 13

Sometimes location manager gives GPS-point, which is located about hundreds meters, or several kilometers away from real device location. After it location manager continues provide us with wrong coordinates, which slowly became closer to real device location.
Such points have quite good accuracy about ~30 - ~65 meters, and some of them have speed > 0 m/s.
real path was:
Authorization status is "Always allow"
location manager is adjustment:
CLLocationManager *manager = [CLLocationManager new];
manager.allowsBackgroundLocationUpdates = YES;
manager.pausesLocationUpdatesAutomatically = NO;
manager.showsBackgroundLocationIndicator = YES;
manager.distanceFilter = 50; // meters
manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
manager.delegate = self;
This problem is actual only for iOS 13. I made about 50 experiments, registering movement trajectories of ~5 km - ~150 km length. Same code works perfectly with iOS 12.

Showing a location with respect to another location without using Map

I am creating a location based iPhone App.
I have two locations (their lat and long).
One location is fixed to center of the UIView, How can show the other location with respect to first location.
Please give me code if available.
If you're just trying to find the distance between your two points then you could use the CoreLocation function:
CLLocation *startLocation = [[CLLocation alloc] initWithLatitude:startLatitude longitude:startLongitude];
CLLocation *endLocation = [[CLLocation alloc] initWithLatitude:endLatitude longitude:endLongitude];
CLLocationDistance distanceMeters = [startLocation distanceFromLocation:endLocation];

Google Maps SDK for iOS How to Identify if a location is within 5 miles of current location?

I have a list of lat/longs that represent the places I want to show on the Google Maps.
How can I check which of these places are near my current location. Something like Near Me functionality that we generally see.
I am using Google Maps SDK for iOS.
Hope the question is clear now?
Make sure that you have imported CoreLocation Framework
CLLocation *locA = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];
CLLocation *locB = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];
CLLocationDistance distance = [locA distanceFromLocation:locB];
//Distance in Meters

How to find out that whether a point on a map is within a radius from user's present location on iOS?

I am new to iOS and I have to make an application in which the the user will know its present location and will enter a value in Kilometers and I have to find out that whether another given pair of latitude and longitude (which give a location on map) is within the given range. Please suggest if we have any function which can used to achieve this.
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
CLLocationDistance is a typedef for double (in meters)
Convert that to kilometers and compare it to the given value.
You obtain user location via CLLocationManager or via MapView's userLocation.
Then you may create a CLRegion and use it's – containsCoordinate: method, like:
CLRegion* region = [[CLRegion alloc] initCircularRegionWithCenter:centerCoord radius:radius identifier:#""];
BOOL isInside = [region containsCoordinate:yourCoord]

CLLocation elevation accuracy

I have a location service app, in which the user's elevation is provided. I have found, though, that the elevation accuracy provided by the CLLocationManager is extremely inaccurate. When I test the same two spots twice, sometimes the elevation difference is forty feet and sometimes it is a hundred. Is there any way that I can improve the vertical accuracy of the CLLocation, or is there a different way of acquiring the user's elevation (third-party libraries)? I have already tried checking the verticalAccuracy property of the newLocation provided by the CLLocationManager and throwing it out if it isn't sufficient, but even when it is 'accurate' enough, it still often isn't actually accurate. Thanks for your time!
Right now I'm using:
if([newLocation verticalAccuracy] < 30) {
if(isCustomary)
altitudeLabel.text = [NSString stringWithFormat:#"%.2f feet", ([newLocation altitude] * 3.2808399)];
else
altitudeLabel.text = [NSString stringWithFormat:#"%.2f meters", [newLocation altitude]];
}
Problems with that code: often the verticalAccuracy never gets below 30, and when it does, that is still not even close to accurate enough; I have tested the code walking around my house (one story), and it says the elevation changes up to nineteen feet, which I'm sure isn't true.
The elevation derived from GPS satellites is inherently less accurate than the horizontal solution from GPS due to the geometry of the satellites. You should expect the vertical accuracy to be usually about 1.5 to 3 times worse than the horizontal accuracy. That's just a limitation of GPS and why aviation requires WAAS correction before you can use GPS for instrument approaches.
When the vertical accuracy is 20 or 30 meters you should expect the altitude to be off up to 100 feet. Expecting it to not vary by 19 feet as you walk around the house in unrealistic.
What you could do is keep a rolling, weighted average (or a Kalman filter) of the recent "good" altitude readings to help filter out the measurement errors.
What code have you tried?
This is the best code for elevation so I don't think there is anything beyond this:
-(void)awakeFromNib {
locmanager = [[CLLocationManager alloc] init];
[locmanager setDelegate:self];
[locmanager setDesiredAccuracy:kCLLocationAccuracyBest];
[locmanager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
heightMesurement.text = [NSString stringWithFormat: #"%.2f m", newLocation.altitude];
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
heightMesurement.text = #"0.00 m";
}

Resources