我使用Obj-C NOT SWIFT在iOS 8中使用Map Kit.我无法获得它设置的设备位置0.00,0.00,我收到错误:
Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
Run Code Online (Sandbox Code Playgroud)
我实施了:(我一次只试过一次,没有运气)
if(IS_OS_8_OR_LATER) {
[self.locationManager requestWhenInUseAuthorization];
[self.locationManager requestAlwaysAuthorization];
}
[self.locationManager startUpdatingLocation];
Run Code Online (Sandbox Code Playgroud)
并在info.plist中
NSLocationWhenInUseUsageDescription : App would like to use your location.
NSLocationAlwaysUsageDescription : App would like to use your location.
Run Code Online (Sandbox Code Playgroud)
我得到提示允许应用程序使用我的位置,但在我同意没有任何变化.该位置显示为0.00,0.00.
显示用户位置的代码:
//Get Location
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];
MKCoordinateRegion region = { { 0.0, 0.0 }, { 0.0, …Run Code Online (Sandbox Code Playgroud) 如何检查我的应用是否启用了位置服务?
我有2个故事板,我想检查位置服务.如果为我的应用启用了位置服务,我想启动带位置的地图故事板.否则,我想发布另一个故事板.我该如何以编程方式完成?
我正在学习如何使用新的Swift语言(只有Swift,没有Objective-C).要做到这一点,我想用map(MKMapView)做一个简单的视图.我想查找并更新用户的位置(例如在Apple Map应用程序中).
我试过了,但没有发生任何事:
import MapKit
import CoreLocation
class MapView : UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var map: MKMapView!
var locationManager: CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
if (CLLocationManager.locationServicesEnabled())
{
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
}
}
}
Run Code Online (Sandbox Code Playgroud)
请你帮助我好吗?
在iOS 6中,不推荐purpose使用CLLocationManager 的属性来描述使用位置服务(@property(copy, nonatomic) NSString *purpose)的原因.
如果有的话,Apple会提出什么替代品?
CLLocationManager在iPhone模拟器上应该假冒库比蒂诺(不是吗?)但它没有,它失败了kCLErrorDomain Code=0.LocationManager的委托接收消息didFailWithError.实现此方法以记录错误,控制台输出以下内容:
Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"
Run Code Online (Sandbox Code Playgroud)
当我遇到这个问题时,我正在研究一个真实的项目,但讨论我的代码是没有意义的,因为我从开发中心下载了"Locations"示例代码(iOS 4更新为2010-06-22)并且问题仍然存在.
当应用程序收到第一个位置更新时,该应用程序将启用"添加"按钮,以便用户可以跟踪其位置,但不执行任何操作.
我添加了一个(普通的)行didFailWithError来记录错误,如果有的话.我得到上述错误.
使用Xcode 3.2.2和目标3.1.3,我可以在运行较旧版本的"Locations"项目时获得固定位置(Cupertino).
有人可以帮忙吗?
谢谢.
我可以MKMapView通过使用纬度和经度对我进行注释,但是,我需要使用位置的源是使用街道地址而不是Lat和Long.例如1234 West 1234 east,San Francisco,CA ...
这有什么关系CLLocationManager吗?
有没有人尝过这个?
我们已经发布了一个在后台运行的应用程序,并使用CoreBluetooth&CoreLocation自动保存您的停车位置.
在较高的水平,我们的应用程序只是寻找CoreBluetooth断开连接事件并打开GPS,直到我们得到一个位置修复(准确度<= 10米)或最多3分钟(这可能发生在你没有GPS覆盖的地下停车场停车) .然后,我们使用重要位置监控在系统终止我们的应用程序时自动重新启动我们的应用程序.
在我们的开发过程中,我们自己从未看到过电池耗尽问题,但是75%的用户表示他们看到电池消耗很大.10%的支持者回应了民意调查,因此很难确定故障的代表性,但我们的用户占很大比例.http://www.findmycarsmarter.com/forum/viewtopic.php?f=4&t=30
然后,我们发布了一项更新,允许用户禁用重要位置监控,60%的人表示,通过禁用重要位置监控,排放消失.http://www.findmycarsmarter.com/forum/viewtopic.php?f=4&t=42
最初我们不能自己复制排水问题,但我们发现当我们安装了一个简单的应用程序,只需将"重要位置监控"与"查找我的汽车智能"结合使用时,我们就会间歇性地看到排水管重现.在排水状态下,手机不会进入休眠状态.这表示即使手机已进入睡眠状态且显示屏已关闭,(设置 - >使用 - >自上次完全充电以来的时间)的使用时间也会继续增加.有些东西会阻止系统进入休眠状态.在这个阶段,电池每小时消耗约15%.这种排水间歇地出现,似乎在一两个小时后自行消失,然后再次随机出现.我们还没有找到一种可靠性来重现排水的方法.
我们认为问题是由多个客户调用CoreLocation引起的.我们询问了一些遇到此问题的用户擦拭手机并只安装了我的Find My Car Smarter应用程序.只安装了这个应用程序,排水管没有展出.我们还有其他报告称,当我们的应用与谷歌纵横或Facebook等一起使用时,他们会看到流失.或者如果他们去杀死其他应用程序,那么排水管就会消失.我们已经看到,在没有应用程序启动的情况下,耗电会持续通过电源循环.这意味着它必须是一个系统级服务,以防止操作系统休眠.
尽管我们认为问题是由多个客户端调用到CoreLocation的一些竞争条件引起的,我们从来没有见过的问题与应用程序,只用CoreLocation重现.我们甚至创建了4个或5个不同的应用程序,这些应用程序将同时访问CoreLocation,我们没有看到排放发生.然而,当我们有一个带有CoreLocation的应用程序和带有CoreLocation + CoreBluetooth的第二个应用程序时,我们确实看到了这个问题.可能很少有应用程序使用CoreLocation + CoreBluetooth组合,所以可能这就是为什么更多的开发人员没有遇到这个问题.虽然我们无法解释CoreLocation和CoreBluetooth如何相互作用导致这种消耗以及CoreLocation的第二个应用程序如何进入这个等式.由于排水是间歇性的,所以这可能只是一个侥幸,这个问题只发生在我们使用CoreLocation + CoreBluetooth进行测试时.
在只有这两个应用程序CTM1和FMC安装的擦除5.0.1 iPhone 4S上,我们能够间歇性地进入排水状态.有趣的是,在我们的普通设备上,擦除设备上的排水问题似乎发生的频率要低得多.不幸的是,我们只看了几次排水状态而且没有能够可靠地再现排水管,我们没有良好的控制状态来工作.
我们已经向Apple提交了一份错误报告并开辟了技术支持事件,但也许Stackover社区也可以提供一些见解.我们在5.0.1和5.1 Beta 3中都看到了这个问题.
CTM1 http://www.findmycarsmarter.com/files/CTM1.zip
On Going into the Background
[locationManager stopUpdatingLocation];
[locationManager stopUpdatingHeading];
[locationManager startMonitoringSignificantLocationChanges];
On Re-entering Foreground
[locationManager stopMonitoringSignificantLocationChanges];
[locationManager startUpdatingLocation];
[locationManager startUpdatingHeading];
On didUpdateToLocation
//do nothing
On didUpdateHeading
//do nothing
Run Code Online (Sandbox Code Playgroud)
FMC http://www.findmycarsmarter.com/files/FMC.zip
On Going into the Background
[btleManager stopScan];
[locationManager stopUpdatingLocation];
[locationManager stopUpdatingHeading];
[locationManager …Run Code Online (Sandbox Code Playgroud) power-management core-location cllocationmanager ios core-bluetooth
我正在尝试使用CLLocationManager我的iOS项目中的框架来访问用户的位置,但是当我打电话时
[locationManager startUpdatingLocation]
Run Code Online (Sandbox Code Playgroud)
既不locationManager:didUpdateLocations:或locationManager:didFailWithError:越来越调用.
//myViewController.h
@interface myViewController : UITableViewController <CLLocationManagerDelegate>
@end
//myViewController.m
@implementation myViewController{
CLLocationManager *locationManager;
}
//edit
- (void)viewDidLoad
{
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
}
//finish edit
-(void)getLocation
{
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error"
message:@"Failed to Get Your Location"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[errorAlert show];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *newLocation = …Run Code Online (Sandbox Code Playgroud) 如何检查用户是否允许mu app的位置?通常我会使用该类的authorizationStatus方法CLLocationManager,但它仅适用于iOS 4.2及更高版本.是否有可能在使用SDK 4.2时以某种方式实现此目的,以便应用程序仍然可以在具有旧版iOS的设备上运行,或者我是否必须降级SDK?沿着同一条线,我需要一个类似于locationServicesEnablediOS 4.0之前的方法的替代方案.
我需要找到我当前的位置CoreLocation,我尝试了多种方法,但到目前为止我CLLocationManager只返回0 ..(0.000.00.000).
这是我的代码(更新后工作):
进口:
#import <CoreLocation/CoreLocation.h>
Run Code Online (Sandbox Code Playgroud)
宣布:
IBOutlet CLLocationManager *locationManager;
IBOutlet UILabel *latLabel;
IBOutlet UILabel *longLabel;
Run Code Online (Sandbox Code Playgroud)
功能:
- (void)getLocation { //Called when needed
latLabel.text = [NSString stringWithFormat:@"%f", locationManager.location.coordinate.latitude];
longLabel.text = [NSString stringWithFormat:@"%f", locationManager.location.coordinate.longitude];
}
- (void)viewDidLoad {
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
}
Run Code Online (Sandbox Code Playgroud) ios ×7
objective-c ×3
iphone ×2
mkmapview ×2
cllocation ×1
cocoa-touch ×1
deprecated ×1
geocoding ×1
ios-4.2 ×1
ios6 ×1
ios8 ×1
location ×1
mapkit ×1
simulator ×1
swift ×1
xcode ×1