【问题标题】:How can I get Latitude and Longitude from Facebook User Location?如何从 Facebook 用户位置获取纬度和经度?
【发布时间】:2014-02-12 01:27:36
【问题描述】:

我设法恢复了下面代码中指定的所有信息,但我无法检索 user.location 的纬度和经度。

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user {
        NSString *fbUsername = [NSString stringWithFormat:@"%@",user.username];
        NSString *fbNickname = [NSString stringWithFormat:@"%@",user.name];
        NSString *fbName = [NSString stringWithFormat:@"%@",user.first_name];
        NSString *fbSurname = [NSString stringWithFormat:@"%@",user.last_name];
        NSString *fbLocation = [NSString stringWithFormat:@"%@",user.location.name];
}

请帮帮我!

【问题讨论】:

  • 我不知道你的问题的答案,但是使用 stringWithFormat:@"%@" 绝对没有意义。摆脱整个结构。它只是让系统无缘无故地进行额外的工作。只需使用 fbName = user.first_name; 之类的代码

标签: ios objective-c facebook-graph-api facebook-fql facebook-login


【解决方案1】:

要获取用户的纬度和经度,请在您发布的方法中尝试:

NSNumber *userLatitude = user.location.location.latitude;
NSNumber *userLatitude = user.location.location.latitude;
//do whatever you want with the values here

【讨论】:

  • 我按照你说的做了,但是这个 NSLog(@"%@",userLatitude);返回(空)
  • @Pinturikkio 不知道是否总是提供值here is the documentation
  • 真的很奇怪!没有一个值返回给我!而且没有解释。也因为地点的名字安全归还给我
【解决方案2】:
     - (void)placePickerViewControllerSelectionDidChange:(FBPlacePickerViewController *)placePicker
 {
// id&#060;
 // FBGraphPlace&#062;
 place = placePicker.selection;


 // we'll use logging to show the simple typed property access to place and location info
 NSLog(@"place=%@, city=%@, state=%@, lat long=%@ %@",
 place.name,
 place.location.city,
 place.location.state,
 place.location.latitude,
 place.location.longitude);
 }

【讨论】:

  • 它不起作用!我该怎么办?没有人可以给我一个解决方案吗?有可能我可以检索到位置的名称,但不能检索纬度和经度(user.location.name)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多