2013-01-19 86 views
6

UIActivityViewController是分享图像和文字的好方法。我怎样才能分享一个位置?为了分享图像和文字,我将相应的对象添加到NSArray,然后我通过UIActivities。我想添加CLLocationCoordinate2D,但这是一个结构,而不是一个对象。我如何使用UIActivityViewController共享位置?

任何想法?

回答

1

我有同样的问题,但找不到通过UIActivityViewController获得坐标工作的答案。

作为一种解决方法,我使用了类似的方法来处理WhatsApp中使用的方法,您可以在其中使用不同的地图提供程序获取操作表。以下代码将显示提醒,并让您选择通过Waze/Google地图/ Apple地图打开特定位置 - 仅显示已安装的应用程序。只需使用CLLocationCoordinate2D纬度/经度属性替换“经度”和“纬度”值即可。

UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; 

UIAlertAction* appleMaps = [UIAlertAction actionWithTitle:@"Open in Maps" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.apple.com/?q=%@,%@", latitude, longitude]]]; 
     }]; 
UIAlertAction* googleMaps = [UIAlertAction actionWithTitle:@"Open in Google Maps" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"comgooglemaps://?q=%@,%@", latitude, longitude]]]; 
     }]; 
UIAlertAction* waze = [UIAlertAction actionWithTitle:@"Open in Waze" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 
      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"waze://?ll=%@,%@", latitude, longitude]]]; 
     }]; 

[alert addAction:appleMaps]; 
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]) 
      [alert addAction:googleMaps]; 
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"waze://"]]) 
      [alert addAction:waze]; 


UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleCancel handler:nil]; 

[alert addAction:cancel]; 

[self presentViewController:alert animated:YES completion:nil]; 
相关问题