如何检查Device iPhone是否已在Xamarin.Forms中设置App Google Maps? [英] How to check Device iPhone has set up App Google Maps in Xamarin.Forms?

查看:100
本文介绍了如何检查Device iPhone是否已在Xamarin.Forms中设置App Google Maps?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题是使用Google Maps打开地图

I have a problem is open maps with Google Maps:

我的设备iPhone已设置App Google Maps,但按按钮时我的应用程序链接到maps应用程序以打开地图.设备打开Safari,不要打开Goog​​le地图.

My device iPhone has set up App Google Maps, but my app when press button links to maps app to open maps. Device opens Safari, don't open Google Maps.

我这样尝试: Xamarin Forms-地图-可以通过按钮调用Google地图吗?

但是在代码行:

var canOpenNative = UIApplication.SharedApplication.CanOpenUrl(NSUrl.FromString("comgooglemaps-x-callback://"));

我无法使用库:`使用 Foundation ;

I can't use library: `using Foundation;

(构建应用将无法使用库.)

(Build app will can't use library.)

我这样尝试:​​ Xamarin.Forms-'Foundation'无法被发现

但是在构建应用程序时,我无法使用库 Foundation 构建.

But when build app I can't build with library Foundation.

那么,还有其他方法,如何检查设备iPhone在Xamarin.Forms中设置了App Google Maps?

So, Has a other ways, How to check Device iPhone sets up App Google Maps in Xamarin.Forms?

谢谢!

推荐答案

如果您尝试从共享代码中使用Foundation程序集,则只能从iOS平台特定的项目中访问它.

If you are trying to use Foundation assembly from your Shared Code then You can only access that from your iOS platform specific project.

您可以使用依赖项服务从共享代码中调用平台特定的代码.请按照以下步骤创建依赖项服务,以检查iPhone是否已安装Google Maps:

You can call platform specific code from your shared code using the dependency services. Follow these steps to create dependency service to check whether IPhone has Google Maps installed:

步骤1:在共享代码中创建接口

Step 1 : Create an Interface in your Shared Code

public interface IMapService
{
     bool HasGoogleMapAvailable();
}

第2步:现在在您的平台特定项目中;现在,它是您的iOS项目.创建将实现您创建的接口的服务:

Step 2 : Now In your platform specific project; For now its your iOS project. Create an Service which will implement the Interface you created:

[assembly: Dependency(typeof(MapService))]
namespace WorkingWithMaps.iOS
{
    public class MapService:IMapService
    {
        public MapService()
        {
        }

        public bool HasGoogleMapAvailable()
        {
            var result=UIApplication.SharedApplication.CanOpenUrl(NSUrl.FromString("comgooglemaps-x-callback://"));
            return result;
        }
    }
}

第3步::在共享代码中,您可以使用该依赖项服务:

Step 3 : In your shared code you can use that Dependency service :

IMapService mapService = DependencyService.Get<IMapService>();
var isInstalled = mapService.HasGoogleMapAvailable();

Console.WriteLine("Google Map is installed :" + isInstalled);

第4步::实际打开地图;您可以使用Device.OpenUri,它将向用户显示弹出窗口,以从设备上所有已安装的地图应用程序中选择任何一个:

Step 4 : To actually open the Map; You can use Device.OpenUri which will show popup to users to select any from all installed map application on the device:

var uri = new Uri("http://maps.google.com/maps?saddr=Google+Inc,+8th+Avenue,+New+York,+NY&daddr=John+F.+Kennedy+International+Airport,+Van+Wyck+Expressway,+Jamaica,+New+York&directionsmode=transit");
Device.OpenUri(uri);

这篇关于如何检查Device iPhone是否已在Xamarin.Forms中设置App Google Maps?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆