簡體   English   中英

Monodroid上的GoogleMaps,Mac上的錯誤編譯

[英]GoogleMaps on Monodroid, Error Compilation on Mac

我如何才能使其在Google API 10(2.3.3)上運行xamarin的Maps Demo ?,我試圖使用Monodroid提供的google maps api運行maps demo應用程序,但它不起作用,它始終顯示為Java.IO。異常:27,Java.IO.Exception:28,依此類推。 自12月以來,我一直在嘗試與之合作,但我沒有看到任何解決方案。 我在Mac上使用Monodevelop IDE工作。 有沒有人有辦法解決嗎?

編輯:

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

這是我對清單的允許:

<?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密鑰不是真正的密鑰。

我使用的是Monodroid,並且我的地圖正在運行..您正在運行演示嗎? 您是否已注冊好debug.kestore並獲得了Google Map API密鑰作為開始? 這是我嘗試使其工作時遇到的一些注意事項

獲取Google Map API密鑰的步驟

=>(注意:Debug.keystore存儲在Xamarin文件夾中,與那些Java應用程序不同)

  1. 安裝Google Inc. SDK
  2. 獲取簽名密鑰指紋
  3. 獲取Map 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]");

這意味着您需要在演示中替換一些代碼

如果您使用的是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並將其動態添加到linearLayout中,它將起作用。 現在,如果您還沒有在應用中顯示地圖,這就是顯示它的方法

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

我意識到我的問題是我的apiKey,我從另一個目錄獲得了指紋:〜/ .android / debug.keystore,我不認為這是問題所在,因為我用它生成了我的apikey並在其中使用了它我的Java android應用程序運行正常,但隨后嘗試將其更改為位於以下目錄中的debug.store:$ HOME / .local / share / Xamarin / Mono for Android / debug.keystore,並給我扔了另一個指紋,因此我用它來生成另一個apikey,然后在Mono上神奇地運行我的應用程序。 但是非常感謝您的幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM