-1

我设法恢复下面的代码中指定的所有信息,但我无法检索user.location的纬度和经度。如何从Facebook用户位置获取经度和纬度?

- (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]; 
} 

请帮帮我!

+1

我不知道回答你的问题,但也绝对没有一点使用stringWithFormat :@“%@”。摆脱整个结构。这只会让系统无缘无故地进行额外的工作。只需使用如fbName = user.first_name; –

回答

1

获得用户的纬度和经度试试这个在您发布的方法:

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

我照你说的做了,但是这个NSLog(@“%@”,userLatitude);返回(空) – Pinturikkio

+0

@Pinturikkio不知道是否总是提供的值这里是文档(https://developers.facebook.com/docs/reference/ios/3.0/protocol/FBGraphLocation) – 68cherries

+0

真的很奇怪!没有任何价值回报给我!没有解释。也因为该位置的名称安全地返回给我 – Pinturikkio

0
 - (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); 
} 
+0

它不工作!我该怎么办?没有人能给我一个解决方案?有可能我可以检索位置的名称,但不能检索纬度和经度(user.location.name) – Pinturikkio

相关问题