2

アプリケーションで Google プレイス API を使用しています。まあ、それはうまく機能し、いくつかの場所で応答を返します。しかし、いくつかの場所では、「ゼロの結果」が得られます。

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://maps.googleapis./maps/api/place/search/json?location=%f,%f&radius=5000&types=&name=%@&sensor=false&key=fgewffefewweweewfe",mapView.centerCoordinate.latitude,mapView.centerCoordinate.longitude,searchPlace.text]];

    NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
    NSURLConnection *connect=  [[NSURLConnection alloc]initWithRequest:request delegate:self];

誰かが私が間違っている場所を教えてもらえますか?

4

1 に答える 1

0

場所の名前が有効でない場合、結果がゼロになり、場合によっては、文字列に余分なスペースがあるため、URL が null として取得されます。したがって、以下で説明したようにコードを更新してチェックしてください。

NSString *googleApi = [NSString stringWithFormat:@"https://maps.googleapis./maps/api/place/search/json?location=%f,%f&radius=5000&types=&name=%@&sensor=false&key=fgewffefewweweewfe",mapView.centerCoordinate.latitude,mapView.centerCoordinate.longitude,searchPlace.text];

NSString *finalURL = [googleApi  stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSURL *url = [NSURL URLWithString:finalURL];

NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
NSURLConnection *connect=  [[NSURLConnection alloc]initWithRequest:request delegate:self];

それはあなたのために働くかもしれません。

于 2012-03-02T12:34:28.573 に答える