I'm trying to make a location based application and I've been trying to debug it for 3 days and still can't figure out whats wrong...In my view controller I am being passed some location points(latitude and longitude) by the delegate method:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
currentPoint.lat=newLocation.coordinate.latitude*M_PI/180;
currentPoint.longit=newLocation.coordinate.longitude*M_PI/180;
}
where currentPoint is an object from the class Pointxy I have created that is nothing more than an object that has two properties lat and longit both floats.
I have then created another class called Shape that has an NSMutableArray (ptArray) and a property called area which is a long double.
I then store a bunch of pointy objects in ptArray and then preform use them in the following Shape method:
-(void)CalculateArea{
for (int i=0; i<[self NumberofPoints]-1; i++) {
Pointxy *pointi=[ptArray objectAtIndex:i];
Pointxy *pointiplus1=[ptArray objectAtIndex:i+1];
area-=6371.0*6371.0/2.0*(pointiplus1.longit-pointi.longit)*(2+sinf(pointiplus1.lat)+sinf(pointi.lat));
}
Pointxy *pointzero=[ptArray objectAtIndex:0];
Pointxy *pointlast=[ptArray objectAtIndex:[ptArray count]-1];
area-=6371.0*6371.0/2.0*(pointzero.longit-pointlast.longit)*(2+sinf(pointzero.lat)+sinf(pointlast.lat));
area=area*1000000.0;
}
The problem I am having is that I then try to display area in an UILabel using this code:
NSString *AreaString=[[NSString alloc]initWithFormat:@"%Lf",MyShape.area];
[AreaLabel setText:AreaString];
where MyShape is a Shape object and AreaLabel is an UILabel, I am always getting 0.0000 displayed and I shouldn't can anyone see why? I guess it is maybe a matter of precision with my variables is it? Thank you very much