我的主.m文件中有以下代码(我想在http查询字符串中发送gps co-ords)
- (CLLocationManager *)locationManager {
if (locationManager != nil) {
return locationManager;
}
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
return locationManager;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *) oldLocation {
NSString *latitudeString = [[NSString alloc] initWithFormat:@"%g°", newLocation.coordinate.latitude];
NSLog(@"lat is %@", latitudeString);
//self.myLatitude = latitudeString;
[latitudeString release];
NSString *longitudeString = [[NSString alloc] initWithFormat:@"%g°", newLocation.coordinate.longitude];
NSLog(@"long is %@", longitudeString);
//self.myLongitude = longitudeString;
[longitudeString release];
}
在我的.h我有:
@interface RootViewController : UITableViewController {
CLLocationManager *locationManager;
}
@property (nonatomic, retain) CLLocationManager *locationManager;
@end
(我已经删除了.h中不必要的行)
如何在不同的代码块中使用上面的当前GPS长/纬度:(代替LONGVAR / LATVAR)
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *tempvariable;
NSString *gpsLat;
switch (indexPath.row) {
case 0:
tempvariable = @"http://randomurl.randomurl.com/mobilesearch/what/Hotels%20and%20Inns/0/0/0/UK/**LONGVAR/LATVAR**/0/0/342/0/0/0/0/0/search.aspx";
break;
case 1:
tempvariable = (@"http://randomurl.randomurl.com/mobilesearch/what/Public%20Houses/0/0/0/UK/**LONGVAR/LATVAR**/0/0/505/0/0/0/0/0/search.aspx");
break;
case 2:
tempvariable = (@"http://randomurl.randomurl.com/mobilesearch/what/All%20Restaurants/0/0/0/UK/**LONGVAR/LATVAR**/0/0/527/0/0/0/0/0/search.aspx");
break;
case 3:
tempvariable = (@"http://randomurl.randomurl.com/mobilesearch/what/Health Care/0/0/0/UK/**LONGVAR/LATVAR**/0/0/843/0/0/0/0/0/search.aspx");
break;
default:
tempvariable = (@"http://randomurl.randomurl.com/mobilesearch/what/Hotels and Inns/0/0/0/UK/**LONGVAR/LATVAR/**0/0/342/0/0/0/0/0/search.aspx");
break;
}
}
答案 0 :(得分:0)
也许我错过了一些东西但只是将newLocation.coordinate.latitude存储在你在头文件中定义的某个浮点值中。
如果您需要在整个应用程序中使用它,可以使用单线类,或将其存储到nsuserdefaults ..