gpt4 book ai didi

objective-c - objective-c -想要获取经度和纬度值并写入GET参数

转载 作者:行者123 更新时间:2023-12-01 19:22:18 25 4
gpt4 key购买 nike

Noob的问题-我用Google搜索,但提出了几个矛盾的答案。我正在实例化CoreLocation,并想将纬度和经度写入url中以获取针对remove服务的信息。我有:

if([CLLocationManager locationServicesEnabled]){
self.myLocationManager=[[CLLocationManager alloc] init];
self.myLocationManager.delegate=self;
self.myLocationManager.purpose = @"To provide functionality based on user's current location";
[self.myLocationManager startUpdatingLocation];
}else{
NSLog(@"Location services are not enabled");
}

NSString *urlAsString=@"http://localhost:3000/";
urlAsString = [urlAsString stringByAppendingString:@"?latitude=my-latitude"];
urlAsString = [urlAsString stringByAppendingString:@"&longititude=my-longitude"];
NSURL *url=[NSURL URLWithString:urlAsString];

如何将纬度和经度正确地写入URL?我是否需要为stringByAppendingString实例化一个新的NSString?

谢谢

最佳答案

使用字符串格式可能会更容易:

NSString *urlAsString = [NSString
stringWithFormat:"http://localhost:3000/?latitude=%g&longitude=%g",
location.coordinate.latitude,
location.coordinate.longitude];

假设您从 %g 实例获取值,我使用了格式说明符 CLLocation

关于objective-c - objective-c -想要获取经度和纬度值并写入GET参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9730707/

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