0

ユーザーの位置を常に追跡するiPhoneアプリを開発しています。

場所は、メートル単位の精度 (最大 400 ~ 500) にすることができます。そして、少なくとも1時間に1回更新する必要があります(ユーザーの場所に変化がなくても、追跡したいと思います)

それを行うための最良の方法は何かを知りたいです。

CLLocation を使用する場合は、1 時間に 1 回 startupdatinglocation を使用してから、startmonitoringsignificantlocationchanges を使用します。バッテリーの消耗を最小限に抑えるための最良の方法だと思いますか

もう1つのオプションはgeoloqiのような位置情報APIを使用することですが、リアルタイム追跡モードを常に使用するとバッテリーが消耗し、パッシブモードでは十分な精度が得られないと思います(私が理解しているように、どの都市のような精度が得られますか)

誰かが私が使用できる推奨API、またはCLLocationを使用して私の問題を解決するための効率的なアルゴリズムについてアイデアを持っていれば幸いです。

ありがとうございました!

4

2 に答える 2

0

このコードを試してみてください。これはうまくいくと思います。.h ファイルにこのコードを追加します

#import "CoreLocation/CoreLocation.h"
#import "MapKit/MapKit.h"

@interface AddressAnnotation : NSObject<MKAnnotation>
{
 CLLocationCoordinate2D coordinate;

  NSString *mTitle;
  NSString *mSubTitle;
}
 @end
 @interface NearestPropertyMatchViewController : UIViewController<MKMapViewDelegate> {

 CLLocationManager *locationManager;
 IBOutlet MKMapView *searchMap;

 NSMutableArray *searchListArray;
 AddressAnnotation *addAnnotation;

}

-(CLLocationCoordinate2D) addressLocation:(NSString *)str;
@property (nonatomic, retain) CLLocationManager *locationManager;

@end

.m ファイルにこのコードを追加します。

   - (void)viewDidLoad
   {
     [super viewDidLoad];
     locationManager = [[CLLocationManager alloc] init];
     locationManager.delegate = self;
      locationManager.desiredAccuracy = kCLLocationAccuracyBest;
     locationManager.distanceFilter = kCLDistanceFilterNone;
     [locationManager startUpdatingLocation];

     CLLocation *location = [locationManager location];


     CLLocationCoordinate2D coordinate = [location coordinate];

      NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
      NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];

     NSLog(@"dLatitude : %@", latitude);
     NSLog(@"dLongitude : %@",longitude);
     MKCoordinateRegion region;
       MKCoordinateSpan span;
      span.latitudeDelta=100;
     span.longitudeDelta=100;
     region.span=span;


for(int i=0;i<[regestrationArray  count];i++)
{
    CLLocationCoordinate2D location = [self addressLocation:[regestrationArray objectAtIndex:i]];


    region.center=location;
    addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location];
    [searchMap addAnnotation:addAnnotation];

    [searchMap setRegion:region animated:TRUE];
    [searchMap regionThatFits:region];   
    }

   -(CLLocationCoordinate2D) addressLocation :(NSString *)str
    {
     NSError* error = nil;
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", 
                       [str  stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSASCIIStringEncoding error:&error];
NSArray *listItems = [locationString componentsSeparatedByString:@","];

double latitude = 0.0;
double longitude = 0.0;

if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
    latitude = [[listItems objectAtIndex:2] doubleValue];
    longitude = [[listItems objectAtIndex:3] doubleValue];
}
else {
    //Show error
}
CLLocationCoordinate2D location;
location.latitude = latitude;
location.longitude = longitude;
NSLog(@" lati=%f lon=%f",latitude,longitude);

return location;

   }

    - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
   {
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
annView.pinColor = MKPinAnnotationColorGreen;
annView.animatesDrop=TRUE;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
return annView;
   }
于 2012-05-05T09:12:28.927 に答える