2

私はこれを理解するのに本当に苦労しています。これに関するPDFSとstackoverflowの質問をたくさん読んだことがありますが、APIを使用したことがなく、静かに手に入れることはできません。経度と緯度の座標を取得し、そこにある API (foursquare、Google マップ、無料でお勧めできる他のものはありますか?) を使用して、近くの公園のリストを取得し、それを NSMutableDictionary key=name オブジェクトに入れようとしています。 =@「距離」。距離と名前だけで、すべてのコンテンツを取得する必要はありません。しかし、私は最初の部分で立ち往生しており、4 時間以上経度と緯度の座標を取得しています。誰でも私にコードを教えてもらえますかhow I would get my coordinates、API を解析する方法を説明する必要はありません。座標を取得したら、それを理解できるように感じます。私はりんごのlocatemeソースコードをダウンロードしましたが、それでも私のものでは動作しません。誰かが提供できる簡単な手順やコードのセットがあり、それを使用してこの頭痛の種を乗り越えることができますか? ロケーションフレームワークをインポートしました。これを解決するための簡単な10〜20行のコードはありますか?3つの追加のView Controllerではなく、私が静かに理解できないほど多くありますか? どうもありがとう

4

2 に答える 2

4
- (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];

}
于 2012-04-20T11:19:19.840 に答える
1

Google Place Apiを使用します。登録するだけで、APIのキーを取得できます。

//APIの例。このAPIは、jsonデータ形式で定義された経度と緯度の半径で食べ物を提供します

https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AddYourOwnKeyHere

Google Place API

願わくば、これはあなたを助けるでしょう..お楽しみください...

于 2012-04-20T10:56:30.130 に答える