gpt4 book ai didi

php - iOS 尝试将位置更新发布到服务器

转载 作者:行者123 更新时间:2023-11-29 11:05:01 25 4
gpt4 key购买 nike

在我的应用程序中,我试图将用户位置的 gps 坐标发布到服务器进行存储,以便我最终可以设计一个显示所有用户位置的 map 。我正在使用 HTTP get 和自定义 PHP API 来处理从应用程序传递到数据库的数据。我遇到的问题是,每次调用 didUpdateLocations 时,我都会更新服务器。它有时会起作用,但有时我的查询字符串会说有一个 undefined variable ,并且正在将空白数据发布到数据库中。为什么有时它是未定义的,有时又不是?另外,有没有更好的方法来处理数据传递?我打算使用 ASIHTTPRequest,但我正在使用 ARC,所以这对我没有帮助。

代码:

- (void)postLocationUpdateFor:(NSString *)deviceToken withDeviceID:(NSString*)deviceID  withLatitude:(NSString *)latitude andLongitude:(NSString *)longitude {

NSString *apiURL = [NSString stringWithFormat:ServerApiURL2, deviceToken, deviceID, latitude, longitude];
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:apiURL]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

NSLog(@"%@", strResult);

}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {

CLLocation *currentLocation = [locations lastObject];

NSString *deviceToken = [[NSUserDefaults standardUserDefaults] stringForKey:@"deviceToken"];
NSString *latitude = [NSString localizedStringWithFormat:@"%f",currentLocation.coordinate.latitude];
NSString *longitude = [NSString localizedStringWithFormat:@"%f",currentLocation.coordinate.longitude];

NSLog(@"Entered new Location with the coordinates Latitude: %@ Longitude: %@", latitude, longitude);

[self postLocationUpdateFor:@"123" withDeviceID:deviceToken withLatitude:latitude andLongitude:longitude];
}

最佳答案

didUpdateLocations

可以在您实际丢失位置时调用:进入电梯/建筑物。这就是为什么有时是空的。

在发送服务器之前,我会检查并验证该位置值。

关于php - iOS 尝试将位置更新发布到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14060174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com