如何使用UIActivityViewController共享位置?

Dan*_*iel 6 iphone

UIActivityViewController是分享图像和文字的好方法.我如何分享位置?为了共享图像和文本,我将相应的对象添加到一个NSArray,然后我将其传递给UIActivities.我想添加CLLocationCoordinate2D,但这是一个结构,而不是一个对象.

有任何想法吗?

小智 2

我遇到了同样的问题,但找不到通过 UIActivityViewController 获取坐标的答案。

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

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];
Run Code Online (Sandbox Code Playgroud)