2

CLLocationManager を使用して現在の場所を取得しています。現在の場所の緯度と経度の値を取得しています。アプリで Mapview を使用していません。したがって、現在の場所が変更されるたびに、その時点で現在の場所をサーバーに更新したいと考えています。そして、5分ごとにWebサービスを呼び出し、バックグラウンドモードとフォアグラウンドモードの両方で現在の場所をサーバーに更新する必要があります。

-(void) getCurrentLocation
{
    // To get the current location of the place
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.distanceFilter = kCLDistanceFilterNone; //whenever we move
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; //100 m
    //Start the location manager, then only updates the current location
    [locationManager startUpdatingLocation];
}

/In Location manager delegate method, if the location is updated it will call and get the values from the newLocation using CLLocation  
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    CLLocation *location = [locationManager location];

    // Configure the new event with information from the location
    CLLocationCoordinate2D coordinate = [location coordinate];

    NSString *lat = [NSString stringWithFormat:@"%f", coordinate.latitude];
    NSString *lon = [NSString stringWithFormat:@"%f", coordinate.longitude];
    NSLog(@"dLatitude : %@", lat);
    NSLog(@"dLongitude : %@",lon);

    self.reverseGeocoder = [[[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate] autorelease];
    reverseGeocoder.delegate = self;
    [reverseGeocoder start];


    //Stop the location manager
    [locationManager stopUpdatingLocation];

}

場所が変更されるたびに、特定の場所の緯度と経度を取得したいと考えています。

ありがとう!

4

3 に答える 3

0

標準の位置情報サービスを使用して (バックグラウンドであっても) ユーザーに継続的な位置情報の更新を提供する必要がある場合は、UIBackgroundModes キー (「位置」値を含む) をアプリの Info.plist ファイル。

于 2014-03-06T02:42:56.037 に答える
-1

まず、プログラムをフォアグラウンドとバックグラウンドで実行する必要がある場合は、プロジェクトの info.plist に位置情報サービスとして必須のバックグラウンド モードを追加します。場所を NSString として取得し、同期型または非同期型を使用して URL をサーバーに投稿してみてください。

于 2012-05-15T14:22:47.837 に答える