【问题标题】:Trying to send POST parameters with latitude and longitude尝试发送带有纬度和经度的 POST 参数
【发布时间】:2015-05-15 13:27:21
【问题描述】:

我正在尝试向我的 phpMyAdmin 表发送一些参数,其中包含一个名为纬度和经度的文件。从那时起,我需要获取设备坐标并将它们转换为字符串。

我已按照 Ray Wenderlich 教程进行操作,但我的参数仍然是“nil”。看看下面的代码:

1 - 我已将框架添加到代码中,并将 CoreLocation 文件导入到我的“ResumeView.h”中,同时声明了纬度和经度字符串。

#import <CoreLocation/CoreLocation.h>

@interface ResumeView : GAITrackedViewController <UIAlertViewDelegate, CLLocationManagerDelegate>
{
NSString *latitude;
NSString *longitude;

2 - 现在,在我的“ResumeView.m”中,我添加了教程后面的其余代码...

@implementation ResumeView {

    CLLocationManager *manager;

}

@synthesize latitude;
@synthesize longitude;

3 - 现在,在 viewDidLoad...

- (void)viewDidLoad
{
    [super viewDidLoad];

    manager = [[CLLocationManager alloc] init];

    manager.delegate = self;

    manager.desiredAccuracy = kCLLocationAccuracyBest;

    [manager startUpdatingLocation];

4 - 然后,这些函数是在我的代码中引入的,当然是在发送 POST 参数之前。

#pragma mark CLLocationManagerDellegate Methods

-(void) locationManager:(CLLocationManager *) manager didFailWithError: (NSError *)error {

    NSLog(@"error: %@", error);
    NSLog(@"Failed to get location! :(");
}

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

    NSLog(@"Location: %@", newLocation);

    CLLocation *currentLocation = newLocation;

    if (currentLocation != nil) {
        latitude = [NSString stringWithFormat: @"%.8f", currentLocation.coordinate.latitude];
        longitude = [NSString stringWithFormat: @"%.8f", currentLocation.coordinate.longitude];
    }
}

5 - 这就是问题所在,两个坐标值都是“nil”,无法发送到数据库。

 @"latitude":latitude, // <---- error here! is nil when sending to database!
 @"longitude":longitude, // <---- error here! is nil when sending to database!

【问题讨论】:

  • 您是否检查过您当前的位置不为零?

标签: ios objective-c location cllocationmanager


【解决方案1】:

您的值为零,因为位置管理器从不向您发送更新。您需要在 iOS 8 中调用一些新功能才能让位置管理器正常工作。以这篇文章为起点:https://stackoverflow.com/a/24063578/78496

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-15
    • 2011-07-06
    • 1970-01-01
    • 2021-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多