gpt4 book ai didi

iphone - 将 iPhone 附近的地点放入简单数组中

转载 作者:行者123 更新时间:2023-12-03 20:31:01 24 4
gpt4 key购买 nike

我真的很难弄清楚这一点。我读过很多关于此的 PDFS 和 stackoverflow 问题,但我从未使用过 API,也无法安静地获取它。我正在尝试获取我的经度和纬度坐标,并使用任何 API(foursquare、谷歌地图、您可以推荐的任何其他免费的?)来获取附近公园的列表,然后将其放入 NSMutableDictionary key=name 对象中=@“距离”。无需获取其所有内容,只需距离和名称即可。但我一直卡在第一部分上,花了 4 个多小时来获取经度和纬度坐标。任何人都可以向我展示代码如何获取坐标,无需解释如何解析 API,一旦我有了坐标,我觉得我可以弄清楚。我已经下载了苹果的locateme源代码,但仍然无法让它在我的上工作。有人可以提供一组易于遵循的步骤或代码,我可以使用并解决这个令人头痛的问题吗?我已经导入了位置框架。是否有一个快速的 10-20 行代码来解决这个问题,而不是 3 个额外的 View Controller ,其中有这么多我不明白的东西。非常感谢

最佳答案

- (void)viewDidLoad
{
[super viewDidLoad];

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
}

#pragma mark Current location methods
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
latit = newLocation.coordinate.latitude;
longit = newLocation.coordinate.longitude;
NSLog(@"latitude = %f",latit);
NSLog(@"longitude = %f",longit);

[manager stopUpdatingLocation];
[self getNearByList];
}

-(void)getNearByList
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyyMMdd"];
NSString *currentDate = [dateFormat stringFromDate:[NSDate date]];
[dateFormat release];

NSURL *url = [NSURL URLWithString:[[NSString stringWithFormat:@"https://api.foursquare.com/v2/venues/search?ll=%f,%f&client_id=YOUR_CLIENT_ID_HERE&client_secret=YOUR_CLIENT_SECRET_HERE&v=%@&limit=100&radius=2000&categoryId=4bf58dd8d48988d1e0931735,4bf58dd8d48988d176941735,4bf58dd8d48988d1ed941735,4bf58dd8d48988d119951735,4bf58dd8d48988d123941735,4d954afda243a5684865b473,4edd64a0c7ddd24ca188df1a,4bf58dd8d48988d1c9941735,4bf58dd8d48988d1bd941735,4bf58dd8d48988d124951735,4bf58dd8d48988d115951735,4bf58dd8d48988d11a951735,4bf58dd8d48988d10c951735,4bf58dd8d48988d11b951735,4bf58dd8d48988d11e951735,4bf58dd8d48988d1f9941735,4bf58dd8d48988d1f5941735,4bf58dd8d48988d113951735,4f04afc02fb6e1c99f3db0bc,4bf58dd8d48988d110951735,4bf58dd8d48988d1f2941735,4bf58dd8d48988d1fd941735,4bf58dd8d48988d103951735,4bf58dd8d48988d104941735,4f04aa0c2fb6e1c99f3db0b8,4d1cf8421a97d635ce361c31,4bf58dd8d48988d1f8941735,4d4b7105d754a06374d81259,4bf58dd8d48988d16d941735,4bf58dd8d48988d128941735,4bf58dd8d48988d111951735,4bf58dd8d48988d1ca941735,4bf58dd8d48988d117951735,4bf58dd8d48988d107951735,4bf58dd8d48988d1fa941735,4bf58dd8d48988d118951735,4bf58dd8d48988d17f941735,4bf58dd8d48988d1ac941735,4bf58dd8d48988d180941735",latit,longit,currentDate] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; //YOU CAN FOUND MORE CATEGORY ID AT FOURSQURE WEBSITE..
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url cachePolicy: NSURLRequestReloadIgnoringCacheData timeoutInterval: 30.f];
NSLog(@"url = %@",urlRequest);
webData1 = [[NSMutableData data] retain];
urlConnection = [[NSURLConnection alloc] initWithRequest: urlRequest delegate: self];
}


-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData1 setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData1 appendData:data];
//NSLog(@"webData1 = %@",webData1);
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Error"
message : @"An error has occured."
delegate:nil
cancelButtonTitle :@"OK"
otherButtonTitles :nil];
[alert1 show];
[alert1 release];

[webData1 release];
[connection release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *data = [[NSString alloc] initWithBytes: [webData1 mutableBytes] length:[webData1 length] encoding:NSUTF8StringEncoding];
NSLog(@"data = %@",data);

[connection release];
[webData1 release];

}

关于iphone - 将 iPhone 附近的地点放入简单数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10244733/

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