Why I am getting the altitude as 0 - iphone

Why I am getting the altitude as 0 while using CoreLocation framework?

Altitude comes from GPS. You need to be outdoors to get altitude.
Take your device outdoor and see if you are getting altitude.

try this
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
altitudeLabel.text = [NSString stringWithFormat: #"%.2f m", newLocation.altitude];
}

Assuming you are testing your application on your device, the altitude will always be 0 when the update comes from Wi-Fi. Try disabling Wi-Fi to force an update from 3G. Note that it may take a while until you get an update because 3G doesn't return a position as fast as Wi-Fi.

Related

How do I calculate my distance from where I am now to a specific point

On my app, I have pin pointed an area on interest. And also the GPS of my location, how would I now let the app calculate and show the user how far the distance away is for them?
My .h file is setup with a map view, a button for finding my location and set map options to choose between map/satellite and hybrid views.
In my .m file I have all the code setting the location and where I am, and also enabled tracking mode. Also setup the different map views and have set a pin point on my map and set the latitude and longitude, then enable Zoom & Scroll function. I have also set so that on the map, when you click on the pinpointed area it says the name and a small description of the place. So everything works fine at this point :D
I really need to find how to find the distance between my point and the pinpointed area.
*please note I am using MapKit!
here if you use bellow code in delegate method of CLLocationManager then its return the distance from your current point to destination point..
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
CLLocation *appleHQ = [[CLLocation alloc] initWithLatitude:37.322998 longitude:-122.032182];////here put your destination point
NSLog(#"New Location:%#", newLocation);
CLLocationDistance distance = [newLocation distanceFromLocation:appleHQ];
NSLog(#"Distance to Apple HQ %4.0f km", distance);
[appleHQ release];
}
just try this code ...
hope,this help you.

GPS and draw MapRout in iphone

I have a latitude and longitude that is fixed, so I used that and got the point in mapview with pin. Now I want the current location and draw route, so I think using gps I get the latitude and longitude. Using this location(latitude & longitude) I have to draw a route with my fixed value (latitude & longitude). How is it possible..? Is this is the right way to do it? ?How to draw the route with two point..?
I have used the delegate method but it doesn't call,
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
[manager stopUpdatingHeading];
NSLog(#"latitude=%f",newLocation.coordinate.latitude);
NSLog(#"longitude=%f",newLocation.coordinate.longitude);
}
I think the best way is using web service from google and draw the points as poly lines to the mapview. I am using http://maps.google.com/maps?f=d&hl=en&saddr=%lf,%lf&daddr=%lf,%lf&ie=UTF8&0&om=0&output=kml web service and draw the routes over mapView as poly lines.You will find an example here to draw polyline over some coordinates.

Find if device is pointing in the right heading / direction?

I would like to find the distance to a location and which direction the device is heading in relation to that location. I've got the distance working but cant work out how to find the which way the location.
_theLocation = [[CLLocation alloc]initWithLatitude:-41.561004 longitude:173.849030];
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLLocationDistance meters = [newLocation distanceFromLocation:_theLocation] * 0.000621371192;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
NSString *str = [NSString stringWithFormat:#"Heading = %.f", newHeading.trueHeading];
}
Is it possible to find the heading to _theLocation from our location?
Can't you simply capture the device's location at two instances & figure out the direction wrt the location?
Not a complete solution, but assuming that the device only moves along the line joining the device & the location, you can use – distanceFromLocation:. If you capture the distance from the location at two instances & see if the latter value is less than the former, you can deduce that the device has moved closer to the location.
In fact, from your question, it appears that you want to determine whether the device has moved closer to the location or not (and not the exact direction, say N or NE). If that's the case, then this should work.
HTH,
Akshay

altitude property in location manager returning zero on Iphone when reading GPS Location

I am writing an app, that uses GPS. I can get successfully the latitude, longitude and other properties, but altitude seems to always return "0.00" i have the following code to test it in the most simplest way and still get 0.00. Code below:
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
// Stop updating location if renewed in less than 60 seconds
if ([self timeBetweenLocationandNow] < 60)
{
[locationManager stopUpdatingLocation];
NSLog(#"GPS Stopped");
}
NSLog(#"Altitude:%.2f m",newLocation.altitude);
}
Any ideas on what could be wrong ? also on an init method i have the following:
- (id)init
{
self = [super init];
if (self != nil)
{
// Create location manager Object
locationManager = [[CLLocationManager alloc] init];
// Set the delegate to this object
[locationManager setDelegate:self];
// Set distance filter and accuracy
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager startUpdatingLocation];
}
return self;
}
Will appreciate any insight. thank you
I'm no expert but this is how I understand it: The iPhone is quite different from other gps systems because of the multiple ways in which it goes about figuring out your location. The iPhone figures out the location in three ways: local wifi signals, cell towers, and/or gps chip. Using a gps satellite to find a position can be extremely slow and reception can be pretty much non-existent in populated cities. Therefore, iPhone generally looks to the first 2 options first.
Wifi positioning data comes from people driving around on the streets logging hotspots which obviously isn't going to give much of a hint of an altitude. I'm not sure if cell tower triangulation gives any altitude data but my guess is no. These two methods are extremely fast compared to gps but will yield an altitude of 0 as you have seen. If you are in a place where there is a decent gps satellite reception the iPhone may give you the altitude, but even then, it might not even find it till it has received the satellite signal a few times and called the location delegate multiple times, and even then altitude data for gps can be notoriously inaccurate.
Long story short, it's a bad idea to count on accurate altitude data from the iPhone.
i found the problem. As Deepmist suggested the delegate has to be called several times. I was stopping the GPS after the first fix. Which was giving me accurate data for coordinates but altitude remained # 0.00 until like 3 or so delegate calls. Now i get the altitude data, what is a good way to check for this ? so i can stop the location manager after i get the data ? i can check that altitude is a non-zero value, but was wondering if there are other properties that should be used instead to make sure that you have the highest accuracy possible making all of your location data valid (i.e non-zero on some properties). thank you

CLLocationManager ensure best accuracy for iphone

Does anyone have any suggestions on how to obtain the best horizontal accuracy on the location manager? I have set the desired accuracy to NearestTenMeters, but given that the accuracy can always change depending on coverage area, how can I write some code in the locationManager to stop updating only after I get the best horizontal accuracy?
If you want it to be to a certain accuracy, set the delegate method
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
to have
if(newLocation.horizontalAccuracy <= (some number) )
[locationManager stopUpdatingLocation];
something like that.
Typically the longer the hardware is on and the more locations it gets the more accurate it gets. You can try turning on the manager early to let it get accurate and then grab the location. It also helps when the target is moving, the chip is able to get more accurate readings when gps is moving. Also the location of the device makes a diffrence, you will get much better reads if you are outside on a field than if you are in a bunker, so sometimes the read you get is the best thats available. Your code can wait till it gets no more updates from location manager for some time, then its probably at its best accuracy.