【发布时间】:2013-12-17 16:46:45
【问题描述】:
好的,所以我的 iOS 应用需要发送纬度和经度以通过 HTTP POST 方法接收郊区。
这是我获取纬度和经度的代码
float lat = locationManager.location.coordinate.latitude;
float lon = locationManager.location.coordinate.longitude;
我想用这样的 HTTP POST 方法发送它
here is the problem
NSString *post = @"key1=val1&key2=val2";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://www.nowhere.com/sendFormHere.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
我想知道是否可以将float 部分更改为字符串或类似于HTTP POST 方法中使用的内容
【问题讨论】:
-
所以问题是我如何将浮点数转换为字符串?之前已经在SO上回答过。顺便说一句,坐标中的纬度和经度字段是
CLLocationDegrees类型,它是双精度型,而不是浮点型。 float 精度不够。
标签: ios string http-post core-location