arkmetal
arkmetal

Reputation: 731

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. Im trying to work with that since December and i dont see any solution of that. Im working on Mac with 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:

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.

Upvotes: 1

Views: 869

Answers (2)

arkmetal
arkmetal

Reputation: 731

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. But thank you very much for your help

Upvotes: 2

lynnyilu
lynnyilu

Reputation: 573

I'm using monodroid and I've got the map working.. you are running the demo? have you got your debug.kestore registered and get the google map API key for a start? here is some notes I had when I was trying to get it work

Steps to obtain google map API key

=> (Note: Debug.keystore is stored in your Xamarin folder, unlike those java apps)

  1. Install Google Inc. Sdk
  2. Obtain signing key fingerprint
  3. Obtain Map API key
  4. Use Map API key in the app

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. but just make a simple map app like theirs and both methods (putting API key in layout file or in the code) will work.

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

[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. If you get ride of the RotateView and just add the mapview to a linearLayout dynamically, it will work. 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.

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

Upvotes: 3

Related Questions