将用户位置发送到 whatsapp 和 facebook

Sending user location to whatsapp and facebook

我正在尝试通过 UIActivityViewController 从我的应用程序将用户位置发送到 facebook 和 whatsapp。

- (IBAction)shareUserLocation:(id)sender {

    shareArray = [[NSArray alloc]initWithObjects:[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.apple.com/maps?q=%f,%f",location.coordinate.latitude,location.coordinate.longitude]],nil];
    UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:shareArray applicationActivities:nil];
    controller.excludedActivityTypes = @[];

    [self presentViewController:controller animated:YES completion:nil];


}

它的工作,但打开苹果地图中的位置。 有什么办法可以在 Google 地图中打开位置。

P.S- 我还没有尝试过 whatsApp 我只测试过 facebook。

如果您想在 Google 地图 iOS 应用程序中打开 Google 地图 URL,可以使用 comgooglemapsurl://maps.google.com/?q=%f,%f。如果你想在浏览器中显示它,你可以做 https://maps.google.com/?q=%f,%f.

示例代码:

-(void)testURL:(CLLocation*)location {

    NSArray *shareArray;
    if ([[UIApplication sharedApplication] canOpenURL:[[NSURL alloc] initWithString:@"comgooglemaps://"]]) {
       shareArray = [[NSArray alloc]initWithObjects:[NSURL URLWithString:[NSString stringWithFormat:@"comgooglemapsurl://maps.google.com/?q=%f,%f",location.coordinate.latitude,location.coordinate.longitude]],nil];

    } else {
        shareArray = [[NSArray alloc]initWithObjects:[NSURL URLWithString:[NSString stringWithFormat:@"https://maps.google.com/?q=%f,%f",location.coordinate.latitude,location.coordinate.longitude]],nil];

    }

    UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:shareArray applicationActivities:nil];
    controller.excludedActivityTypes = @[];
    [self presentViewController:controller animated:YES completion:nil];
}