2012-01-30 46 views
1

我如何使它在Google API 10(2.3.3)上運行xamarin的地圖演示?,即時通訊試圖運行Monodroid提供的google maps API地圖演示應用程序,它不起作用,它總是出現Java.IO.Exception:27,Java.IO.Exception:28等等。我試圖與自12月以來的工作,我沒有看到任何解決方案。我使用Monodevelop IDE在Mac上工作。有沒有人有辦法解決嗎?Monodroid上的GoogleMaps,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" 
    /> 

這裏是我的清單權限:

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

回答

2

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

3

我正在使用monodroid,我有地圖工作..你正在運行演示?你有你的debug.kestore註冊並獲得谷歌地圖API密鑰的一個開始?這裏是一些筆記,當我試圖得到它的工作

Steps to obtain google map API key

=>我(注:Debug.keystore存儲在您的Xamarin文件夾,不像Java應用程序)

  1. 安裝谷歌公司的SDK
  2. 獲得簽名密鑰指紋
  3. 獲取地圖API密鑰的應用
  4. 使用地圖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> 

不知道這是必要的,但在集信息。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,只需動態地將mapview添加到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; } 
        } 
    } 
    
+0

我在Eclipse IDE中使用它,並且工作正常。我像我之前說的那樣替換了我的Api鍵,並且它總是返回這些異常:無法獲得連接工廠客戶端,IOException處理:26,java.io.IOException:服務器返回3等等,因爲我知道代碼是好的,我認爲它可能是別的,正如我之前提到的,我正在開發Google Googles API 10(2.3.3)。我需要一個解決方案,而不是使用另一個API版本。 – arkmetal 2012-01-31 19:18:43

+0

好吧,我明白你的意思了。如果您正在使用MapsDemo,啓動活動中有兩個選項是正確的嗎? MapView給你的錯誤和MapView和指南針工作正常,顯示地圖和所有,但也顯示輸出中的一些不同的錯誤?無論如何,這就是我的情況,而這正是我開始開發我的應用時發生的事情。只要您可以從「MapView和Compass」中看到地圖,就可以開發您的應用了。 – lynnyilu 2012-02-01 00:33:04

+0

我不是確定演示中發生了什麼,但是我可以爲我的應用使用相同的代碼,並且沒有錯誤,只要您添加了正確的權限即可。你所說的錯誤類似於當你只看到灰色網格時會發生什麼。無法獲得連接工廠客戶端......單聲道做了很多,所以沒關係。如果是這種情況,你可以運行應用程序,但只看到灰色網格,然後檢查上面的權限,我編輯了答案 – lynnyilu 2012-02-01 00:36:18