iPhone GPS 给出不正确的位置

发布于 2024-11-19 03:56:03 字数 1503 浏览 2 评论 0原文

我想使用 iPhone GPS 功能显示用户的当前位置,但问题是它给出的位置不正确。 当我在地图上放置图钉时,它会将图钉放置在准确的位置,但是当我尝试查看文本中的位置时,它会给出不准确的位置,误差约为 500 到 800 米。我使用了反向地理编码和 google api,但都给出了相同的位置。请告诉我为什么会发生这种情况以及如何显示用户的确切位置? 我的代码是:

cllocationmanager *locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
        locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
        locationManager.desiredAccuracy = kCLLocationAccuracyBest; // 100 m
        [locationManager startUpdatingLocation];


    }

    }



- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation

{


 CLLocationCoordinate2D here =  newLocation.coordinate;
    NSLog(@"%f  %f ", here.latitude, here.longitude);


    MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:here];
    [geocoder setDelegate:self];
    [geocoder start];

        }



- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{



}



- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
    NSLog(@"The geocoder has returned: %@", [placemark addressDictionary]);



    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat:@"%@",[placemark addressDictionary]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
    [alertView release];


}

I want to show user's current location with iphone gps feature but problem is it is giving incorrect location .
When i drop pin on map then it drops pin at exact position but when i try to see the location in text then it gives inaccurate location with inaccuracy of 500 to 800 meters approx.I have used reverse geocoding and google api but all giving same location. PLease tell me why this happens and how can i show the exact location of user ?
My code is:

cllocationmanager *locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
        locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
        locationManager.desiredAccuracy = kCLLocationAccuracyBest; // 100 m
        [locationManager startUpdatingLocation];


    }

    }



- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation

{


 CLLocationCoordinate2D here =  newLocation.coordinate;
    NSLog(@"%f  %f ", here.latitude, here.longitude);


    MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:here];
    [geocoder setDelegate:self];
    [geocoder start];

        }



- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{



}



- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
    NSLog(@"The geocoder has returned: %@", [placemark addressDictionary]);



    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat:@"%@",[placemark addressDictionary]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
    [alertView release];


}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若无相欠,怎会相见 2024-11-26 03:56:03

快速猜测:您检查过 CLLocation 的水平精度吗?通常,我得到的第一个响应非常不准确,然后后续的呼叫就会变得更好。

编辑:@pankaj 首先,您能否确认这是一个准确性问题。如果这是我建议的问题,那么 CLLocation Horizo​​ntalAccuracy 将会很大。如果不是这样,那么您可以忽略我的回答和这些评论。但是,如果horizo​​ntalAccuracy 误差较大,那么您将不得不等待更好的锁定。有两种方法可以做到这一点:

  1. 等待一小段时间(一两秒),看看是否获得更好的锁定。
  2. 更早地开始请求位置,例如当应用程序启动时,或者当需要位置的 UIViewController 启动时。

Quick guess: did you check the CLLocation's horizontal accuracy? Quite often the first response I get is very inaccurate, and then subsequent calls get better.

Edit: @pankaj First of all, can you confirm that it is an accuracy issue. If it is the problem that I'm suggesting, then the CLLocation horizontalAccuracy will be large. If not the case then you can ignore my answer and these comments. However, if horizontalAccuracy is a large error then you will have to wait for a better lock. There are two ways to do this:

  1. Wait for a short period of time (a second or two) and see if you get a better lock.
  2. Start requesting location much earlier on, e.g. when the app launches, or when the UIViewController that requires location starts.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文