您的 URl 显示您想列出当前位置附近的地点。
为此,您需要当前位置坐标、半径、搜索到的地名和关键字。
做这个:
第 1 步:添加 CoreLocation 框架
第 2 步:#导入
第 3 步:添加 CLLocationManagerDelegate 委托
第四步:制作 CLLocationManager *locationManager;
第 5 步:初始化 CLLocationManager(通常在 ViewDidLoad 中)
self.locationManager = [[CLLocationManager alloc] init];// autorelease];
// This is the most important property to set for the manager. It ultimately determines how the manager will
// attempt to acquire location and thus, the amount of power that will be consumed.
locationManager.desiredAccuracy = kCLLocationAccuracyBest ;
// Once configured, the location manager must be "started".
[locationManager startUpdatingLocation];
locationManager.delegate = self;
第 6 步:为 CLLocationManager 编写代码
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
StrCurrentLongitude=[NSString stringWithFormat: @"%f", newLocation.coordinate.longitude]; // string value
StrCurrentLatitude=[NSString stringWithFormat: @"%f", newLocation.coordinate.latitude];
appDeleg.newlocation=newLocation;
[locationManager stopUpdatingLocation]; // string Value
}
第 7 步:使用坐标和开火请求:
[NSURL URLWithString:[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/xml?location=%@,%@&radius=%@&name=%@&sensor=false&key=YOU-API-KEY",StrCurrentLatitude,StrCurrentLongitude,appDeleg.strRadius,strSelectedCategory]
请享用