1

この Google Places API の URL を使用して 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"];

ユーザーの現在の場所を緯度/経度で保存し、それらの値を NSURL に配置することは問題でしょうか?

助けてくれてありがとう

4

1 に答える 1

3

あなたの 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]

楽しい

于 2012-08-21T10:44:31.853 に答える