views:

64

answers:

2

HI all,

I was using a sample code which uses CLLocationManager class to determine the current location of user. when i run this app on iPad i am getting the correct location but when i run the same app on iPod Touch i am getting a blank label i.e nothing is displayed on the label .although wi-fi signal strength is good in both iPod and iPad.The code looks like...

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation{




     int degrees = newLocation.coordinate.latitude;

    double decimal = fabs(newLocation.coordinate.latitude - degrees);
    int minutes = decimal * 60;
     double seconds = decimal * 3600 - minutes * 60;
NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
                 degrees, minutes, seconds];


    latLabel.text = lat;
    [latLocationArray addObject:lat]; 






degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
                   degrees, minutes, seconds];
longLabel.text = longt;
 [longLocationArray addObject:longt];

}

+1  A: 

It's possible that the iPad is seeing WiFi stations that the iPod Touch can't see. The Touch has a smaller WiFi range. Are you testing in an area with very few WiFi stations (the countryside).

Is the iPad a 3G model? If it is, it will use GPS and cell towers if WiFi isn't working.

Have you checked any errors that the location manager is sending back to you? You might have disabled location data for the app previously, or there may be some other error.

nevan
but signal strength is very good here although i hv nt checked the eroors
Siddharth
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{ NSLog(@"error=%@",error); }i have use this method now but it is not called.
Siddharth
Your own WiFi signal strength is not really what matters. WiFi location works by looking at all the WiFi stations around you and trying to find one that's in a large database. The database matches WiFi and location, but if none of the WiFi stations near you are in that database, you can't get a location. That's why WiFi density is important (ie the number of WiFi stations near you). Here's a nice description: http://www.skyhookwireless.com/howitworks/
nevan
thanks nevan.....but in such case the error method should invoke....it is also not getting called..
Siddharth
The "can't find location" error usually takes a while to come up. As a test, you could try the maps app on your iPod Touch. Does it find any location? If maps can find a location, the problem is with your code.
nevan
thanks nevan....but the same code is running well for iPad.
Siddharth
A: 
int degrees = newLocation.coordinate.latitude;

double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;

You're aware that all these machinations have a net result of '0' when newLocation.coordinate.latitude >= 0, correct?

if newLocation.coordinate.latitude = 90.....

degrees = 90
decimal = 0; (90 - 90)
minutes = 0; (0 * 60)
seconds = 0; (0 * 3600 - 0 * 60) // assuming typical operand precedence

KevinDTimm
i dint realize that...thanks kevin
Siddharth