![](/img/trans.png)
[英]How to get near by places in radius of 2 kilometer from current location without using Google API in iOS Objective C
[英]How to find current user location to use in Google Places API for iOS
我希望使用此Google Places API网址在iOS应用中进行搜索。 我想使用用户的当前位置,而不是使用指定的位置:
NSURL *googlePlacesURL = [NSURL URLWithString:@"https://maps.googleapis.com/maps/api/place/search/xml?location=34.0522222,-118.2427778&radius=500&types=spa&sensor=false&key=AIzaSyAgcp4KtiTYifDSkIqd4-1IPBHCsU0r2_I"];
是存储用户当前位置lat / lon然后将这些值放在NSURL中的问题吗?
谢谢你的帮助
您的URl显示您要列出当前位置附近的位置。
为此你需要当前的位置坐标,半径,搜索的地名和密钥。
做这个:
第1步:添加CoreLocation框架
第2步:#import
第3步:添加CLLocationManagerDelegate委托
第4步:创建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]
请享用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.