jdog
jdog

Reputation: 10759

Incompatible types in initialization?

Why am I getting "incompatible types in initialization" in the following code?

NSString *latString = [NSString stringWithFormat:@"%@", @"-44.4349773"];
    NSString *lngString = [NSString stringWithFormat:@"%@", @"-33.2779787"];
    double latDouble = [latString doubleValue];
    double lngDouble = [lngString doubleValue];
    double roundDouble = 0;
    NSNumber *mylngDoubleNumber;
    if(latDouble == 0 && lngDouble == 0) {
        NSNumber *mylngDoubleNumber = 0;
    }else{
double tempDble = [self calcDiffDistance:latDouble withPostLng:lngDouble ]; <-- incompatible types...
NSNumber *mylngDoubleNumber = [NSNumber numberWithDouble:tempDble];



-(double)calcDiffDistance:(double )postLat withPostLng:(double )lon1 {

NSLog(@"beginning CLLocationDegrees in calcDiff in UsersPosts");
CLLocationDegrees lat = self.lastKnownLocation.coordinate.latitude;
CLLocationDegrees lng = self.lastKnownLocation.coordinate.longitude;
NSLog(@"finsished CLLocationDegrees in calcDiff in UsersPosts");

NSLog(@"beginning location1 in calcDiff in UsersPosts");
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:postLat longitude:lon1];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:-44.4343 longitude:-34.977];
NSLog(@"finsished CLLocationDegrees in calcDiff in UsersPosts");


NSLog(@"beginning location release in calcDiff in UsersPosts");
double target = [location1 distanceFromLocation:location2];
//int myInt = (int)ceil(target);
target = target/1609.334;
[location1 release];
[location2 release];
NSLog(@"finsished location release in calcDiff in UsersPosts");

return target;

}

.h code ////////////////////////////////

                                                      #import <UIKit/UIKit.h>
    #import "PostTableCustomCellController.h"
    #import "LoadMoreResultsTableViewCell.h"
    #include <stdlib.h>
    #import "CLController.h"
    #import <CoreLocation/CoreLocation.h>


    @class PostDetailViewController;

    @interface TransactionsTableViewController : UITableViewController <CLControllerDelegate, UIScrollViewDelegate, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate> {
        IBOutlet UITableView *transactionsTableView;
        NSMutableArray *postsArray;
        PostDetailViewController *postDetailViewController;
        UITableView *transTableView;
        Boolean *isFetchingData;
        int *webServiceAllCount;
        NSCalendar *calendar;
        NSTimer *minuteTimer;
        NSTimer *regionsTimer;
        Boolean *blockRefresh;
        CLLocation *lastKnownLocation;
    }

    @property (nonatomic, retain) CLLocation *lastKnownLocation;
    @property Boolean *blockRefresh;
    @property (nonatomic, assign) Boolean *isFetchingData;
    @property (nonatomic, retain) LoadMoreResultsTableViewCell *loadMoreResultsCell;
    @property (nonatomic, assign) NSTimer *minuteTimer;
    @property (nonatomic, assign) NSTimer *regionsTimer;


    -(double)calcDiffDistance:(double )postLat withPostLng:(double )lon1;
    - (NSString *)dateDiff:(NSString *)origDate;
    - (void)updateTime:(NSTimer *)timer;
    - (void)updateRegions;
    -(void)newLocationUpdate:(CLLocation *)location;
    -(void)newError:(NSString *)text;
    @property (nonatomic, retain) UITableView *transTableView;
    @property (nonatomic, retain) NSMutableArray *postsArray;
    @property (nonatomic, retain) PostDetailViewController *postDetailViewController;

    @end

Upvotes: 2

Views: 3246

Answers (4)

meronix
meronix

Reputation: 6176

@jgervin: the good new is that i i tried your code in my project at it works, with no error at all...

that's the report in my debugger console:

[2745:207] beginning CLLocationDegrees in calcDiff in UsersPosts [2745:207] finsished CLLocationDegrees in calcDiff in UsersPosts [2745:207] beginning location1 in calcDiff in UsersPosts [2745:207] finsished CLLocationDegrees in calcDiff in UsersPosts [2745:207] beginning location release in calcDiff in UsersPosts [2745:207] finsished location release in calcDiff in UsersPosts [2745:207] __:79893040

i just added your code:

-(double)calcDiffDistance:(double )postLat withPostLng:(double )lon1 {

    NSLog(@"beginning CLLocationDegrees in calcDiff in UsersPosts");
//  CLLocationDegrees lat = self.lastKnownLocation.coordinate.latitude;  // not used
//  CLLocationDegrees lng = self.lastKnownLocation.coordinate.longitude; // not used
    NSLog(@"finsished CLLocationDegrees in calcDiff in UsersPosts");

    NSLog(@"beginning location1 in calcDiff in UsersPosts");
    CLLocation *location1 = [[CLLocation alloc] initWithLatitude:postLat longitude:lon1];
    CLLocation *location2 = [[CLLocation alloc] initWithLatitude:-44.4343 longitude:-34.977];
    NSLog(@"finsished CLLocationDegrees in calcDiff in UsersPosts");


    NSLog(@"beginning location release in calcDiff in UsersPosts");
    double target = [location1 distanceFromLocation:location2];
    //int myInt = (int)ceil(target);
    target = target/1609.334;
    [location1 release];
    [location2 release];
    NSLog(@"finsished location release in calcDiff in UsersPosts");

    return target;
}

calling this from somewhere in my code:

NSString *latString = [NSString stringWithFormat:@"%@", @"-44.4349773"];
NSString *lngString = [NSString stringWithFormat:@"%@", @"-33.2779787"];
    double latDouble = [latString doubleValue];
    double lngDouble = [lngString doubleValue];
    double roundDouble = 0; // not used
    NSNumber *mylngDoubleNumber; // not used
    if(latDouble == 0 && lngDouble == 0) {
        NSNumber *mylngDoubleNumber = 0; // not used
    }else{
        double tempDble = [self calcDiffDistance:latDouble withPostLng:lngDouble ]; //
        NSNumber *mylngDoubleNumber = [NSNumber numberWithDouble:tempDble];
        NSLog(@"____:%d", mylngDoubleNumber);
    }   

with this in .h file:

#include <stdlib.h> //
#import <CoreLocation/CoreLocation.h> //

and:

-(double)calcDiffDistance:(double )postLat withPostLng:(double )lon1;

so your compiler error is to search somewhere else, not a declaration method error the bad new is that i don't know where...

and... your method return different (unexpected) values every time ... like here:

__:100906736

__:100786912

__:79891648

...

ps

i guess you imported the right framework "CoreLocation.framework" in your project, of course...

Upvotes: 0

bbum
bbum

Reputation: 162722

Best guess w/o seeing the context within which that code is compiled is that you aren't importing the header file that declares the method calcDiffDistance:withPostLng:.

Also, an instance variabel of type int* is almost assuredly not what you meant; do you really want a pointer to an int?!

This method name is a bit rough, too:

-(double)calcDiffDistance:(double )postLat withPostLng:(double )lon1 {

How about something like this:

-(double)calculateDistanceFromLatitude:(double)lat longitude:(double)long

?

Upvotes: 3

visakh7
visakh7

Reputation: 26400

Pls check the data type of the variables latDouble and lngDouble. It has to be double.

Upvotes: 1

Ishu
Ishu

Reputation: 12787

You are passing here latDouble and lngDouble in calcDiffDistance method.And type for these argument does not match with method argument types.see the declration statement.

type for latDouble and lngDouble must be double.

Upvotes: 0

Related Questions