【问题标题】:GoogleMaps on Monodroid, Error Compilation on MacMonodroid 上的 Google 地图,Mac 上的错误编译
【发布时间】:2012-01-30 15:09:36
【问题描述】:

我怎样才能让它在谷歌的 API 10 (2.3.3) 上运行 xamarin 的地图演示?,我试图用 Monodroid 提供的谷歌地图 api 运行地图演示应用程序,但它不起作用,它总是出现 Java .IO.Exception:27,Java.IO.Exception:28,依此类推。自 12 月以来,我一直在尝试使用它,但我没有看到任何解决方案。我正在使用 Monodevelop IDE 在 Mac 上工作。有没有人有办法解决吗?

编辑:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="match_parent" 
android:layout_height="match_parent">
<com.google.android.maps.MapView
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:enabled="true"
    android:clickable="true"
    android:apiKey="0oqo66omATbRfB2Wpsdf6Kpi9-fm88CsqwHauLg"
    />

这是我对 Manifest 的许可:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="cdcsoftwareerpmobileandroid.cdcsoftwareerpmobileandroid">
<application android:label="CdcSoftware.ErpMobile.AndroidUI" android:debuggable="true">
</application>
<uses-permission android:name="android.permission.CALL_PHONE">
</uses-permission>
<uses-permission android:name="android.permission.INTERNET">
</uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION">
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION">
</uses-permission>
<uses-sdk /></manifest>

这是 MapActivity 类,我评论了一行来测试这两个选项:

public class MapAddress : MapActivity
{
    const String TAG = "MapViewCompassDemo";

    private SensorManager sensor_manager;
    private RotateView rotate_view;
    private MyLocationOverlay location_overlay;

    protected override void OnCreate (Bundle savedInstanceState)
    {
        base.OnCreate (savedInstanceState);
        //SetContentView (Resource.Layout.mapview);


        // Get a reference to the sensor manager
        sensor_manager = (SensorManager) GetSystemService (Context.SensorService);

        // Create our view
        var map_view = new MapView (this, "0oqo66dsfTbRfB2Wp0Lr6Kpi9-fm88CsqwHauLg");

        rotate_view = new RotateView (this);
        rotate_view.AddView (map_view);

        SetContentView (rotate_view);

        // Create the location overlay
        location_overlay = new MyLocationOverlay (this, map_view);
        location_overlay.RunOnFirstFix (delegate {
            map_view.Controller.AnimateTo (location_overlay.MyLocation);
        });
        map_view.Overlays.Add (location_overlay);

        map_view.Controller.SetZoom(18);
        map_view.Clickable = true;
        map_view.Enabled = true;
    }

    protected override bool IsRouteDisplayed {
        get { return false; }
    }
}

注意:那里的 Api Key 不是真实的。

【问题讨论】:

    标签: c# android google-maps xamarin.android


    【解决方案1】:

    我正在使用 monodroid,我的地图可以正常工作。你正在运行演示吗?你有没有注册你的 debug.kestore 并获得谷歌地图 API 密钥作为开始?这是我尝试让它工作时的一些笔记

    Steps to obtain google map API key

    =>(注意:Debug.keystore 存储在您的 Xamarin 文件夹中,与那些 java 应用不同)

    1. 安装 Google Inc. SDK
    2. 获取签名密钥指纹
    3. 获取地图 API 密钥
    4. 在应用中使用 Map API 密钥

    之后,要显示地图,请使用

    <com.google.android.maps.MapView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:enabled="true"
        android:clickable="true"
        android:apiKey="[MY API KEY]" />
    

    或以编程方式:

    var map_view = new MapView (this, "[MY API KEY]");
    

    这意味着你需要替换Demo中的一些代码

    如果您使用 Mono 的 MapDemo,不知何故,只有带指南针的那个对我有用。但只需像他们一样制作一个简单的地图应用程序,这两种方法(将 API 密钥放入布局文件或代码中)都可以工作。

    编辑:

    对于权限,将这些放在应用程序标记之外:

      <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
      <uses-permission android:name="android.permission.INTERNET" />
      <application></application>
    

    不确定这是否有必要,但在 AssemblyInfo.cs 中

    [assembly: UsesPermission(Android.Manifest.Permission.Internet)]
    

    对我来说,我只是像这样在布局中加载地图:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
      <Button
          android:id="@+id/Logout"
          android:layout_alignParentTop="true"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="@string/Logout"
        />
      <com.google.android.maps.MapView
          android:id="@+id/mapview"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_below ="@+id/Logout"
          android:layout_alignParentLeft="true"
          android:enabled="true"
          android:clickable="true"
          android:apiKey="API KEY"
            />
      <LinearLayout android:id="@+id/zoom"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_centerHorizontal="true"
      />
    </RelativeLayout>
    

    并像这样加载它:

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle); ;
        SetContentView(Resource.Layout.mapview);
    ...
    }
    

    编辑:

    刚刚评论了一些部分以使您的代码正常工作:

    注意:

    1. 我认为传感器和 RotateView 有问题,因为我无法让它以这种方式工作。如果您使用 RotateView 并将地图视图动态添加到线性布局,它将起作用。目前,如果您的应用中还没有显示地图,这就是如何显示它

    2. 我将 SetContentView (Resource.Layout.Main) 更改为我放置 MapView 布局的位置.. 只需将其更改回您的位置即可。

      public class MapAddress : MapActivity
      {
          const String TAG = "MapViewCompassDemo";
          //private SensorManager sensor_manager;
          //private RotateView rotate_view;
          //private MyLocationOverlay location_overlay;   
          protected override void OnCreate (Bundle savedInstanceState)
          {
              base.OnCreate (savedInstanceState);
              SetContentView (Resource.Layout.Main);
      
      
              // Get a reference to the sensor manager
          //    sensor_manager = (SensorManager) GetSystemService (Context.SensorService);
      
              // Create our view
        /*      var map_view = new MapView (this, "0oeB7V1XvegNHY25V5kJq0dsGz_HPbzZa-0WCkg");
      
              rotate_view = new RotateView (this);
              rotate_view.AddView (map_view);
      
              SetContentView (rotate_view);
      
              // Create the location overlay
              location_overlay = new MyLocationOverlay (this, map_view);
              location_overlay.RunOnFirstFix (delegate {
                  map_view.Controller.AnimateTo (location_overlay.MyLocation);
              });
              map_view.Overlays.Add (location_overlay);
      
              map_view.Controller.SetZoom(18);
              map_view.Clickable = true;
              map_view.Enabled = true;
              */
          }
      
          protected override bool IsRouteDisplayed {
              get { return false; }
          }
      }
      

    【讨论】:

    • 我在 Eclipse IDE 中使用它,并且工作正常。我像你之前所说的那样替换了我的 Api 密钥,它总是返回这些异常:无法获取连接工厂客户端,IOException 处理:26,java.io.IOException:服务器返回 3 等等,因为我知道代码没问题,我认为它可能是别的东西,正如我之前提到的,我在 Googles API 10(2.3.3) 上开发。我需要一个解决方案,而不是使用另一个 API 版本。
    • 好吧,我明白你的意思了。如果您使用的是 MapsDemo,启动活动中有 2 个选项对吗? MapView 给你错误,MapView 和 Compass 工作正常,显示地图,但在输出中还显示一些不同的错误?反正我就是这样,当我开始开发我的应用程序时就是这样。只要您可以从“MapView 和指南针”中看到地图,您就可以开发您的应用程序了..
    • 我不太确定演示中发生了什么,但我可以为我的应用程序使用相同的代码并且没有错误,只要您添加了正确的权限。你所说的那种错误就像你只看到灰色网格时会发生什么。无法获得连接工厂客户端是…… Mono 做了很多事情,所以没关系。如果是这种情况,您可以运行应用程序但只看到灰色网格然后检查上面的权限,我编辑了答案
    • 好的。我复制了您的代码,并从中提出了解决方案,是的,它给出了您所说的错误。我进行了 2 处更改以显示地图:1. 将 API 密钥更改为我的有效 debug.keystore API 密钥 2. 将活动中的代码更改为上面,正如我在答案中编辑的那样。
    • 我意识到我的问题是我的 apiKey,我从另一个目录获得了我的指纹:~/.android/debug.keystore 我不认为这是问题,因为我用它生成是为了获取我的 apikey 并在我的 Java android 应用程序中使用它并且工作正常,但随后我尝试将其更改为位于此目录中的 debug.store:$HOME/.local/share/Xamarin/Mono for Android/debug .keystore,然后扔给我另一个指纹,所以我用它来生成另一个 apikey,然后神奇地在 Mono 上运行我的应用程序。但是非常感谢您的帮助。
    【解决方案2】:

    我意识到我的问题是我的 apiKey,我从另一个目录获得了我的指纹:~/.android/debug.keystore,我不认为这是问题,因为我用它生成以获得我的 apikey,我在我的 Java android 应用程序中使用它并且工作正常,但后来我尝试将其更改为位于此目录中的 debug.store:$HOME/.local/share/Xamarin/Mono for Android/debug.keystore,然后抛出我另一个指纹,所以我用它来生成另一个 apikey,然后神奇地在 Mono 上运行我的应用程序。不过非常感谢您的帮助

    【讨论】:

      猜你喜欢
      • 2016-03-06
      • 1970-01-01
      • 2017-09-15
      • 1970-01-01
      • 2011-04-14
      • 1970-01-01
      • 1970-01-01
      • 2013-12-11
      • 2016-02-08
      相关资源
      最近更新 更多