![](/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.