【问题标题】:MKMapView User Location Timeout using Parse.com使用 Parse.com 的 MKMapView 用户位置超时
【发布时间】:2014-12-17 10:26:21
【问题描述】:

所以我使用 parse 从该查询中获取用户位置和数据的更新,如下所示:

-(void) getUserLocationAndData:(BOOL) showProgress
{
    [PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error)
     {
         if (!error)
         {
             NSLog(@"Got current location - Zooming Map!");
             CLLocationCoordinate2D zoomLocation;
             zoomLocation.latitude  = geoPoint.latitude;
             zoomLocation.longitude = geoPoint.longitude;

             [self getNearByData:geoPoint];
         }
         else
         {
             [[[UIAlertView alloc] initWithTitle:@"Unable to get Current Location" message:@"This app needs your current location in order to locate near by data. Please check your internet connection and make sure you enabled access to the location information." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil] show];
         }
     }];
}

当应用首次启动时,用户位置会显示出来,数据会被提取并且一切正常。如果您等待大约 15 秒并且不移动用户位置图标将变为灰色(见图)并且任何更新都会导致失败。如果我重新加载视图,它会再次工作,但会发生同样的事情。

我没有使用 CLLocationManager,因为我不需要不断地将数据拉到用户附近。只是每隔一段时间或根据用户的要求。

我还注意到,如果我等待足够长的时间,用户位置会再次变为蓝色,并且似乎一切正常。是什么导致此超时?我可以设置这个超时,还是只需要使用 CLLocationManager 来控制它? Parse 是否只是因内部 CLLocationManager 或其他原因而超时?

感谢您的帮助!

【问题讨论】:

    标签: ios parse-platform mkmapview cllocationmanager cllocation


    【解决方案1】:

    显然,当您使用 Parse 函数时:geoPointForCurrentLocationInBackground Parse 将接管它自己的内部 CLLocationManager。在它完成之后,它会停止更新位置(或者可能仅在用户移动足够多的情况下才更新用户位置..在这里再次猜测..以及设备是否支持该功能)。

    解决方案是在视图控制器中创建自己的 CLLocationManager 而不是调用

    geoPointForCurrentLocationInBackground 
    

    您只需存储更新的用户位置并调用:

    PFGeoPoint *usersGeoPoint = [PFGeoPoint geoPointWithLocation:usersLastKnownLocation];
    

    现在我们可以使用它来查询附近的数据。我们现在负责启动和停止用户位置的更新。我强烈建议使用这篇文章来设置您自己的 LocationManager 并确保向下滚动到更新的答案以获取更多最新信息。 How can I get current location from user in iOS

    在阅读 Parse 文档中的 geoPointWithLocation 后,我得出了上述结论。请自己阅读(我知道它真的很难找到,只有一行......)

    【讨论】:

      猜你喜欢
      • 2011-11-14
      • 1970-01-01
      • 2011-01-04
      • 2016-08-22
      • 2011-08-16
      • 2011-08-29
      • 1970-01-01
      • 2011-09-18
      • 2011-08-11
      相关资源
      最近更新 更多