每当用户登录时,我都会呼叫当前位置,以及其他几个地方.每当我这样做时,请求用户许可的警报视图会出现一秒左右,然后它就会消失.显然,我没有得到这个位置.每当我提示位置时都会发生这种情况.它不允许用户单击"取消"或"确定".请帮忙
我正在尝试编码地图上的注释,但我读到我无法对CLLocationcoordinate2D变量进行编码.有谁知道我怎么解决这个问题?这是一些代码.
这是我放下引脚的地方:
- (void)press:(UILongPressGestureRecognizer *)recognizer {
CGPoint touchPoint = [recognizer locationInView:_worldView];
CLLocationCoordinate2D touchMapCoordinate = [_worldView convertPoint:touchPoint toCoordinateFromView:_worldView];
geocoder = [[CLGeocoder alloc]init];
CLLocation *location = [[CLLocation alloc]initWithCoordinate:touchMapCoordinate
altitude:CLLocationDistanceMax
horizontalAccuracy:kCLLocationAccuracyBest
verticalAccuracy:kCLLocationAccuracyBest
timestamp:[NSDate date]];
[geocoder reverseGeocodeLocation:location
completionHandler:^(NSArray *placemarks, NSError *error) {
//NSLog(@"reverseGeocoder:completionHandler: called");
if (error) {
//NSLog(@"Geocoder failed with error: %@", error);
} else {
CLPlacemark *place = [placemarks objectAtIndex:0];
geocodedAddress = [NSString stringWithFormat:@"%@ %@, %@ %@", [place subThoroughfare], [place thoroughfare], [place locality], [place administrativeArea]];
if (UIGestureRecognizerStateBegan == [recognizer state]) {
value = …Run Code Online (Sandbox Code Playgroud) 我正在编写一个带有mapView的应用程序,其中显示了一些注释.
现在我想在mapView中显示用户的当前位置.我使用以下代码获取当前位置:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)location
Run Code Online (Sandbox Code Playgroud)
我在日志中获得了当前位置的详细信息
2013-10-14 12:03:34.291 AppName[13200:a0b] (
"<+7.35000000,+47.32000000> +/- 5.00m (speed -1.00 mps / course -1.00) @ 10/14/13, 12:03:34 PM Central European Summer Time")
Run Code Online (Sandbox Code Playgroud)
现在我没有把这个位置放到mapView中作为这个蓝色脉冲点.
请给出一些提示.
我为这个主题的冗余道歉,但是尽管给出了所有给出的答案,我还是无法确定在终止应用程序时获得accuracyBest位置更新的可能性.我不想使用monitoringSignificantChange,我希望尽可能准确; 我不会在AppStore上提交应用程序,因此Apple的限制也不是问题.
我经历过这些:
还有更多,但目前尚不清楚,有可能与否.我目前有我的项目,一切都与significantChange很好,但我现在需要更高的准确性.
有人可以直接告诉我,如果获得应用程序被杀的最佳准确位置更新吗?
非常感谢你,
我正在开发GPS应用程序.你知道如何检测移动设备的速度吗?
实际上,我需要每2秒检测一次速度.
我知道didUpdateToLocation当位置改变时调用方法.
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
Run Code Online (Sandbox Code Playgroud)
但我认为这种方法不适合我的问题.
那么,我需要[CLLocationManager location]在2秒内检查速度吗?
有什么建议吗?
提前致谢.
我正在尝试使用distanceFromLocation:方法来计算我手里拿着iPhone走的总距离.到目前为止,我一直在寻找帮助解决我混乱,不准确和看似随意的结果.在这些代码片段中,theLabel只是我的应用程序界面中的标签对象,distanceMoved是我试图存储我走进的总距离的变量,locMan是在我的@interface文件中声明的位置管理器.
- (void)viewDidLoad
{
locMan = [[CLLocationManager alloc] init];
locMan.delegate = self;
[locMan startUpdatingLocation];
isInitial = true;
distanceMoved = 0.0;
[super viewDidLoad];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
distanceMoved += [newLocation distanceFromLocation: oldLocation];
theLabel.text = [NSString stringWithFormat: @"%f meters", distanceMoved];
}
Run Code Online (Sandbox Code Playgroud)
任何有助于解决我在这里做错的帮助将不胜感激.谢谢!
如何计算在Swift中使用CoreLocation的总行程距离
到目前为止,我还没有找到任何有关如何在Swift for iOS 8中执行此操作的资源,
您如何计算自开始追踪您的位置以来移动的总距离?
从我到目前为止所读到的,我需要保存点的位置,然后计算当前点和最后一点之间的距离,然后将该距离添加到totalDistance变量
Objective-C对我来说是非常陌生的,所以我无法解决swift语法问题
这是我到目前为止所做的,不确定我是否做得对.虽然该distanceFromLocation方法返回所有0.0所以显然有些错误
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
var newLocation: CLLocation = locations[0] as CLLocation
oldLocationArray.append(newLocation)
var totalDistance = CLLocationDistance()
var oldLocation = oldLocationArray.last
var distanceTraveled = newLocation.distanceFromLocation(oldLocation)
totalDistance += distanceTraveled
println(distanceTraveled)
}
Run Code Online (Sandbox Code Playgroud) 我需要使用以下内容构建一个数组:
CLLocationCoordinate2D points[4];
points[0] = CLLocationCoordinate2DMake(41.000512, -109.050116);
points[1] = CLLocationCoordinate2DMake(41.002371, -102.052066);
points[2] = CLLocationCoordinate2DMake(36.993076, -102.041981);
points[3] = CLLocationCoordinate2DMake(36.99892, -109.045267);
Run Code Online (Sandbox Code Playgroud)
问题是,我永远不会知道数组中有多少项,所以我可以指定计数.有没有办法创建一个CLLocationCoordinate2D数组,只是插入新的坐标而不知道最终的总数是多少?
编辑:我的最终目标是使用坐标来制作MKPolyline,使用需要CLLocationCoordinate2D数组的polylineWithCoordinates方法.
委托方法基本上是一半的时间
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;
Run Code Online (Sandbox Code Playgroud)
完全没有被召唤.但另一半时间它完美运作!我发现它通常发生在我关闭并退出它之后第一次启动Xcode时,但之后在那之后或者几次运行之后它似乎工作正常.我不是100%肯定,如果它只是一个Xcode问题或什么,我很快就会得到开发人员的许可证,所以我会看看它是否能在实际设备上正常工作.
从viewDidAppear开始(在viewDidLoad中尝试也没有区别),我运行一个方法来初始化我的locationManager东西:
locationManager = [[CLLocationManager alloc]init];
[locationManager setDelegate:self];
locationManager.distanceFilter = 20.0f;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.pausesLocationUpdatesAutomatically = NO;
if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
[locationManager requestAlwaysAuthorization];
[locationManager startUpdatingLocation];
Run Code Online (Sandbox Code Playgroud)
有时候这种方法有效,有时则不然.我甚至做了一个计时器,每隔一秒钟就重新运行一次,但这不起作用.
还有什么我应该做的吗?这个问题有什么答案吗?
谢谢.
如何获取当前位置的经纬度.
我试过这个.使用Xcode 6.01和IOS SDK 8.0
-(CLLocationCoordinate2D) getLocation{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
return coordinate;
}
- (void)getCurrentLocation{
CLLocationCoordinate2D coordinate = [self getLocation];
NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];
NSLog(@"Latitude = %@", latitude);
NSLog(@"Longitude = %@", longitude);
}
- (void)viewDidLoad{
[super viewDidLoad];
[self getCurrentLocation];
}
Run Code Online (Sandbox Code Playgroud)
在这里,我将模拟器位置启用到Deployment 8.0 iPhone模拟器4s.即使在设备上也无法正常工作.
@ALL请告诉我,我在这里做错了什么.
core-location cllocationmanager cllocation currentlocation ios8
cllocation ×10
ios ×6
objective-c ×5
iphone ×4
mkmapview ×2
xcode ×2
background ×1
ios7 ×1
ios8 ×1
location ×1
nscoding ×1
performance ×1
swift ×1
terminate ×1