in iphone is there any alternate way of CLLocation to find location - iphone

I am not getting accuracy by using CLLocation
CLLocation *locA = [[CLLocation alloc] initWithLatitude:CurrentUserLocationNow.latitude longitude:CurrentUserLocationNow.longitude];
locB = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude];
distance = [locA distanceFromLocation:locB];
int feet = distance*3.28084;
if(feet >= 40)
{
[avaudioplayer stop];
}
but I am not getting perfect accuracy

CLLocation class method distanceFromLocation is the easiest way to find the distance between two points on map. Talking about your accuracy that you can set with the help of your CLLocationManager desiredAccuracy property to kCLLocationAccuracyBest.
But if you using the google direction api in your project you can do from by parsing the json.(Hectic task)

There is no way in iOS to garner location without using CLLocation. There may be 3rd party libraries that allow you to get location, but they would all just be wrappers for CLLocation. Apple does not allow access to the GPS hardware any other way. So if you need location, you are basically stuck with CLLocation.

Related

Two different GPS locations given from same code

So I'm very very very very new to programming, but I've fumbled my way through this far: I'm creating an Iphone App,
My goal is to create an automatic stopwatch; something that starts itself at a pre-set location and stops itself at a pre-set location ( both of which are set by the user). If the pre-set gps location and the actual gps location are equal, a timer will start/stop. I've done this by setting a location as a variable at the push of a button.
here's the problem: The two values are never equal. The pre-set start and finish locations contain many more decimals than the "actual" location ( the values themselves, not just the printed values) and if they are never equal, the timer will not start.
any help is appreciated!!!!
You could simply calculate the distance between the two coordinates and start/stop the timer when the distance drops below a certain threshold (e.g. 50m) to the start or end location.
CLLocation provides a convient method for doing so:
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
For example:
double lat = 51.7;
double lng = 7.0;
CLLocation *locationStart = [[CLLocation alloc] initWithLatitude:lat longitude:lng];
CLLocation *currentLocation = ...; // received from location services
if ([locationStart distanceFromLocation:currentLocation] < 50) {
// start timer
}
You may also consider using the horizontalAccuracy property of the current location instead of the arbitrary 50m. Beware however that the accuracy can be as bad as several kilometers. Something like MIN(horizontalAccuracy, 50) may work well.

Detect if user enters or leaves a region - geocoding

I'm starting with geocoding. And I have a lot of doubts.
I'm able to do forward and reverse geocoding (I guess, its not perfect).
And now, I'm trying to detect if user (device) enters or leaves a region. For that, I picked up apple's sample code "Regions". The sample uses regionMonitoring. I already try it in a device, but its not working well. I set a region with 25 meters radius, and when I left the region (walking) doesn't happen anything.
My question is: there is another and better way of doing this, detect if user enters or leaves a region, than regionMonitoring?
Can someone help me here??
Thanks a lot.
you could keep the user-location tracking running in the background (here is a good tutorial) but keep in mind this can be heavier on battery use than regionMonitoring.
I found a solution to calculate the distance between two CLLocationCoordinate2D it is easier than I though:
- (CLLocationDistance) DistanceBetweenCoordinate:(CLLocationCoordinate2D)originCoordinate andCoordinate:(CLLocationCoordinate2D)destinationCoordinate {
CLLocation *originLocation = [[CLLocation alloc] initWithLatitude:originCoordinate.latitude longitude:originCoordinate.longitude];
CLLocation *destinationLocation = [[CLLocation alloc] initWithLatitude:destinationCoordinate.latitude longitude:destinationCoordinate.longitude];
CLLocationDistance distance = [originLocation distanceFromLocation:destinationLocation];
[originLocation release];
[destinationLocation release];
return distance;
}

How to calculate distance to locations

I've developed an iPhone application to parse data from an XML file. This data contains a set of longitudes and latitudes for different places.
How do I detect nearest of them according to my current location on the map and how do I set set a range to show places in this range?
CLLocation *myLocation = [[CLLocation alloc] initWithLatitude:myLatitude longitude:myLongitude];
CLLocation *myXmlLocation = [[CLLocation alloc] initWithLatitude:xmlLatitude longitude:xmlLongitude];
CLLocationDistance distance = [myLocation distanceFromLocation: myXmlLocation];
This is in meters, so you must do any converting from there. They are also linear, so these aren't driving direction lengths by any means. Good luck.
some trig, but really not too difficult.
this page has an example script, not in your language, but it contains explainations and the equations you need.
http://www.movable-type.co.uk/scripts/latlong.html
and also, please don't write run-on sentences, it took me a while to read your question.
#Vinnie said is absolutely right but these values is air distance.
Also this method is deprecated in iOS 3.2
- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location Parameters
You can't find the distance based on roads with the Apple SDK. Try to use google APIs for finding distance between two points on earth on roads.

Calculate distance between two locations using google map in iphone

I just want to calculate distance between two location .
In which user can enter both the location's addresses, and from that addresses I want to calculate the distance between them.
Is it possible to calculate distance from CLLocation using these addresses ?
First you need to geocode the address to latitude/longitude, then you can use the CLLocation framework to calculate the distance.
To geocode the adress, you could use this forward geocoding API.
// get CLLocation fot both addresses
CLLocation *location = [[CLLocation alloc] initWithLatitude:address.latitude longitude:address.longitude];
// calculate distance between them
CLLocationDistance distance = [firstLocation distanceFromLocation:secondLocation];

iPhone sdk MapDistance

Can anyone help me "How to calculate distance between two places in MAP(CLLocation).Tell the delegates,methods etc to be used .
Thanks in advance,
BrightRaj
Does this help?
distanceFromLocation - Calculate distance between two points
You can use this method in CLLocation that takes another CLLocation object and returns the distance in meters:
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
Be aware that it's available only in iOS ≥3.2. If you wanna target older iOS versions, use
- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location
This method is marked as deprecated and will disappear at some time in the future.