6

UIActivityViewController是共享图像和文本的好方法。我如何也可以共享位置?为了共享图像和文本,我将相应的对象添加到 中NSArray,然后将其作为UIActivities. 我只想添加CLLocationCoordinate2D,但那是一个结构,而不是一个对象。

有任何想法吗?

4

1 回答 1

2

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

作为一种解决方法,我使用了与我在 WhatsApp 中看到的类似的方法,您可以在其中获得包含不同地图提供者的操作表。以下代码将显示警报,让您选择通过 Waze/Google Maps/Apple Maps 打开特定位置 - 只有已安装的应用程序才会显示。只需用您的 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];
于 2015-03-02T20:48:51.653 回答