首页 \ 问答 \ Lat,Long值对iphone中的当前位置不准确(Lat,Long values are not accurate to the current location in iphone)

Lat,Long值对iphone中的当前位置不准确(Lat,Long values are not accurate to the current location in iphone)

我是新手IOS现在我正在开发位置应用程序我在iPhone中运行我的应用程序时没有得到正确的纬度,经度值..它给了我太远的lat,长值到当前位置为什么它显示我这些值可以让任何人告诉我..


I am new to IOS now I am developing location app i am not getting correct latitude,longitude values while running my app in iPhone.. it gives me too far lat,long values to the current location why it shows me these values can anyone tell me..


原文:https://stackoverflow.com/questions/14622136
更新时间:2019-07-12 07:09

最满意答案

尝试一下....

设置委托CLLocationManagerDelegate

#import <CoreLocation/CoreLocation.h>

CLLocationManager *locationManager;
CLLocation *startLocation;


- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *currentLatitude;
    NSString *currentLongitude;
    locationManager = [[CLLocationManager alloc] init];
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.delegate = self;
    [locationManager startUpdatingLocation];
    startLocation = nil;
 }

-(void)locationManager:(CLLocationManager *)manager
   didUpdateToLocation:(CLLocation *)newLocation
          fromLocation:(CLLocation *)oldLocation
{
    currentLatitude = [[NSString alloc] 
                   initWithFormat:@"%g", 
                   newLocation.coordinate.latitude];



    currentLongitude = [[NSString alloc] 
                    initWithFormat:@"%g",
                    newLocation.coordinate.longitude];

   NSLog(@"%@",currentLatitude);
   NSLog(@"%@",currentLongitude);
}

-(void)locationManager:(CLLocationManager *)manager 
  didFailWithError:(NSError *)error
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"ERROR" message:[NSString stringWithFormat:@"%@",error] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
    [alert release];
}

Try it....

Set Delegate CLLocationManagerDelegate

#import <CoreLocation/CoreLocation.h>

CLLocationManager *locationManager;
CLLocation *startLocation;


- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *currentLatitude;
    NSString *currentLongitude;
    locationManager = [[CLLocationManager alloc] init];
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.delegate = self;
    [locationManager startUpdatingLocation];
    startLocation = nil;
 }

-(void)locationManager:(CLLocationManager *)manager
   didUpdateToLocation:(CLLocation *)newLocation
          fromLocation:(CLLocation *)oldLocation
{
    currentLatitude = [[NSString alloc] 
                   initWithFormat:@"%g", 
                   newLocation.coordinate.latitude];



    currentLongitude = [[NSString alloc] 
                    initWithFormat:@"%g",
                    newLocation.coordinate.longitude];

   NSLog(@"%@",currentLatitude);
   NSLog(@"%@",currentLongitude);
}

-(void)locationManager:(CLLocationManager *)manager 
  didFailWithError:(NSError *)error
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"ERROR" message:[NSString stringWithFormat:@"%@",error] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
    [alert release];
}
2013-04-01

相关问答

更多

iPhone SDK中的GPS读数准确度如何?(How accurate is the reading for GPS in iPhone's SDK?)

最好的准确度似乎是9米。 常见的值(室外,覆盖范围)为17米,23米和49米。 树木覆盖着天空,你可能会呆在一百米以内,但对于GIS或其他任何类似的东西来说,几乎不够精确。 The best possible accuracy seems to be 9 meters. Common values (outdoor, good coverage) is 17 m, 23 m and 49 meters. With trees covering the sky you'll probably sta ...

确定从iPhone CoreLocation返回最准确的确定算法?(Definitive algorithm for determining most accurate returned from iPhone CoreLocation?)

这不是一个确定的,完美的算法(我怀疑这个任务有一个,因为外部条件,我的意思是,你可以尝试在普通场地或坟墓内获得你的位置),这是一个特殊的算法,它为我工作。 我为LocationManager做了一个包装器,就像 @protocol LocationManagerWrapperDelegate <NSObject> @required - (void) locationUpdated: (CLLocation *) locationUpdate; - (void) errorOccured: ( ...

复制地图跟随Android中的当前位置功能(Replicating Maps Follow Current Location Feature in Android)

Google Maps v2中还没有正式的方法可以做到这一点。 但是你可以做你想做的事。 你必须做两件事: 注册一些LocationProviders(例如gps)的位置更新以获取用户的位置。 当您获得位置动画地图到新位置时。 当用户移动地图时停止此操作。 所以做1.很容易,做2.正确使用Maps v2 api。 请查看此问题以获取更多详细信息。 解决方法建议创建自己的MapView(扩展原始MapView)并覆盖它的dispatchTouchEvent方法。 在那里,您可以捕获任何触摸事件,并可 ...

确定准确的iPhone电池电量(Determine accurate iPhone battery level)

尽管我看不到任何代码有任何特别的错误,请尝试以下操作 - (void)viewDidLoad { [super viewDidLoad]; UIDevice *device = [UIDevice currentDevice]; device.batteryMonitoringEnabled = YES; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(batter ...

在Android中获取用户位置的好方法(Good way of getting the user's location in Android)

看起来我们正在编码相同的应用程序;-) 这是我目前的实现。 我仍然在GPS上传器应用程序的beta测试阶段,因此可能会有许多可能的改进。 但是到目前为止,它似乎工作得很好。 /** * try to get the 'best' location selected from all providers */ private Location getBestLocation() { Location gpslocation = getLocationByProvider(Location ...

如何在iPhone SDK中使用MapKit访问当前位置的所有餐厅?(How to access all restaurants from my current Location using MapKit in iPhone SDK?)

这可以帮助你,使用谷歌地图的API: http : //code.google.com/intl/vi-VN/apis/maps/documentation/places/#PlaceSearches This may help you, using API of Google Map : http://code.google.com/intl/vi-VN/apis/maps/documentation/places/#PlaceSearches

获取访客的当前位置(Get current location of a visitor)

navigator.geolocation.getCurrentPosition( onSuccess, onError, { enableHighAccuracy: true, timeout: 20000, maximumAge: 120000 }); function onSuccess(position) { //the following are available to use //p ...

在iPhone上的GoogleMaps上获取我的位置时崩溃(Crash while getting my location on GoogleMaps on iPhone)

已经在评论中说过了...... GMSMapView必须Strong如果你没有调用requestWhenInUseAuthorization你的代码在iOS 8中requestWhenInUseAuthorization 我建议你只使用CLLocationManager代替KVO ...但是你的决定。 附上我的例子 - 我用2个例子修改了Google示例... 与KVO 仅限CLLocationManager 如果您有任何问题......请告诉我 PS别忘了添加API密钥 快乐的编码! UPDAT ...

相关文章

更多

最新问答

更多
  • Android宽度:100%修复(网站接管问题)(Android width:100% fix (website takeover issue))
  • C ++函数/方法设计的良好实践(Good practice in C++ function/method design)
  • 计算其他表中不存在的所有记录 - SQL查询(Count all records that does not exist to other table - SQL Query)
  • 为什么我要用JPA共享ID?(Why do I get shared Ids with JPA?)
  • asp.net - 如何显示来自html格式的数据行的字段(asp.net - how to display a field from data row that is in html format)
  • 我们如何使用ActiveRecord从连接表中删除行?(How can we delete rows from a join table by using ActiveRecord?)
  • ng-class搞乱了类的顺序(ng-class messing with the order of classes)
  • oracle 12g无效数字错误(oracle 12g invalid number error)
  • 更改ng-src值onclick(Change ng-src value onclick)
  • 如何在android中自动添加自定义依赖项以创建新项目?(How to add custom dependencies automatically in android for ever a new project is created?)
  • datetime函数在PHP中(datetime function in php)
  • 在javascript中获取会话数组的值(in javascript get the value of a session array)
  • 如何在UTF8中编译LaTeX?(How can I compile LaTeX in UTF8? [closed])
  • Rspec:“array.should == another_array”,但不用担心订单(Rspec: “array.should == another_array” but without concern for order)
  • Logcat错误:无法在android片段中加载视图(Logcat error: unable to load view in android fragments)
  • JavaFX的。(JavaFX. Adding items to the list in different threads is not working)
  • 从GDATA日历资源迁移到Google Calendar Resource api(Migrate from GDATA calendar resource to Google Calendar Resource api)
  • SSRS 2008 - 以零情景处理分割(SSRS 2008 - Dealing with division by zero scenarios)
  • 我如何以编程方式添加一个listView列标题的点击事件(How can I add a listView column header a click event programmatically)
  • Wxpython:无法检索有关列表控件项XXX的信息(Wxpython: Couldn't retrieve information about list control item XXX)
  • 使用Tortoise SVN在SVN存储库中移动目录(Move Directory across SVN repository using Tortoise SVN)
  • 天蓝色服务结构集群中的web api无状态服务是否在一段时间不活动后进入休眠状态?(Do web api stateless services in azure service fabric cluster go to sleep after a period of inactivity?)
  • 我可以设置intelliJ来突出显示PHP编码风格吗?(Can I set intelliJ to highlight php coding style?)
  • 用javafx创建一个Truetype字体文件(Creating a Truetype Font file with javafx)
  • Spring ftp配置错误(Spring ftp configuration is wrong)
  • 使用gsub去除多个字符(Using gsub to strip multiple characters)
  • 续订推送证书并保持当前的App Store App正常工作(Renew Push certificate and keep current App Store App working)
  • js:ES5和ES6之间关于'this'关键字用法的一个令人困惑的观点(js: one confusing point about 'this' keyword usage between ES5 and ES6)
  • window.onload vs $(document).ready()(window.onload vs $(document).ready())
  • 在Swift中,如何声明一个符合一个或多个协议的特定类型的变量?(In Swift, how can I declare a variable of a specific type that conforms to one or more protocols?)