繁体   English   中英

iPhone和Google Places API

[英]iPhone & Google Places API

我在应用程序中使用Google Place 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];

谁能告诉我我哪里出错了?

如果位置名称无效,它将给您零结果;在某些情况下,由于字符串中有多余的空格,您将获得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];

它可能为您工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM