简体   繁体   English

Monodroid上的GoogleMaps,Mac上的错误编译

[英]GoogleMaps on Monodroid, Error Compilation on Mac

How can i make it work the Maps Demo of xamarin on Google's API 10 (2.3.3)?, im trying to run the maps demo app with the google maps api that Monodroid provides and it doesnt work, it always appear Java.IO.Exception: 27, Java.IO.Exception: 28, and so on. 我如何才能使其在Google API 10(2.3.3)上运行xamarin的Maps Demo ?,我试图使用Monodroid提供的google maps api运行maps demo应用程序,但它不起作用,它始终显示为Java.IO。异常:27,Java.IO.Exception:28,依此类推。 Im trying to work with that since December and i dont see any solution of that. 自12月以来,我一直在尝试与之合作,但我没有看到任何解决方案。 Im working on Mac with Monodevelop IDE. 我在Mac上使用Monodevelop IDE工作。 Does anyone have a solution? 有没有人有办法解决吗?

Edit: 编辑:

<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"
    />

Here is my permission on the 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>

And this is the MapActivity Class which i commented a line to test both options: 这是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; }
    }
}

Note: The Api Key there is not the real one. 注意:Api密钥不是真正的密钥。

I'm using monodroid and I've got the map working.. you are running the demo? 我使用的是Monodroid,并且我的地图正在运行..您正在运行演示吗? have you got your debug.kestore registered and get the google map API key for a start? 您是否已注册好debug.kestore并获得了Google Map API密钥作为开始? here is some notes I had when I was trying to get it work 这是我尝试使其工作时遇到的一些注意事项

Steps to obtain google map API key 获取Google Map API密钥的步骤

=> (Note: Debug.keystore is stored in your Xamarin folder, unlike those java apps) =>(注意:Debug.keystore存储在Xamarin文件夹中,与那些Java应用程序不同)

  1. Install Google Inc. Sdk 安装Google Inc. SDK
  2. Obtain signing key fingerprint 获取签名密钥指纹
  3. Obtain Map API key 获取Map API密钥
  4. Use Map API key in the app 在应用程序中使用Map API密钥

After that, to display map, use 之后,要显示地图,请使用

<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]" />

Or programatically: 或以编程方式:

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

This means you need to substitute some codes in the Demo 这意味着您需要在演示中替换一些代码

if you are using the MapDemo from Mono, somehow only the one with compass works for me. 如果您使用的是Mono的MapDemo,则某种程度上只有带指南针的那个对我有用。 but just make a simple map app like theirs and both methods (putting API key in layout file or in the code) will work. 但是只需制作一个像它们一样的简单地图应用即可,这两种方法(将API密钥放入布局文件或代码中)都可以使用。

Edit: 编辑:

For permissions, put these outside the application tag: 要获得权限,请将这些放在应用程序标签之外:

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

not sure if this is necessary but in the AssemblyInfo.cs 不知道这是否必要,但在AssemblyInfo.cs中

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

for me I simply load a map in the layout like this: 对我来说,我只是像这样在布局中加载地图:

<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>

and load it like this: 并像这样加载它:

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

EDIT: 编辑:

Just commented some parts to get your code working: 刚刚注释了一些部分,以使您的代码正常工作:

Note: 注意:

  1. I'm supposing there is something wrong with the sensor and the RotateView because I cannot get it working that way. 我猜想传感器和RotateView出了点问题,因为我无法使其正常工作。 If you get ride of the RotateView and just add the mapview to a linearLayout dynamically, it will work. 如果您使用RotateView并将其动态添加到linearLayout中,它将起作用。 For now, if you haven't get the map shown in your app, this is how to show it 现在,如果您还没有在应用中显示地图,这就是显示它的方法

  2. I changed SetContentView (Resource.Layout.Main) to where I put my MapView layout.. just change it back to yours. 我将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; } } } 

I realize that my problem was my apiKey, i got my fingerprint from another directory: ~/.android/debug.keystore and i didnt think that was the problem, because i generate with it in order to obtain my apikey and i use it in my Java android app and was working fine, but then i try change it to the debug.store that is located in this directory: $HOME/.local/share/Xamarin/Mono for Android/debug.keystore, and throws me another fingerprint, so i use it to generate another apikey, and then magically works my app on Mono. 我意识到我的问题是我的apiKey,我从另一个目录获得了指纹:〜/ .android / debug.keystore,我不认为这是问题所在,因为我用它生成了我的apikey并在其中使用了它我的Java android应用程序运行正常,但随后尝试将其更改为位于以下目录中的debug.store:$ HOME / .local / share / Xamarin / Mono for Android / debug.keystore,并给我扔了另一个指纹,因此我用它来生成另一个apikey,然后在Mono上神奇地运行我的应用程序。 But thank you very much for your help 但是非常感谢您的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM