我怎样才能让它在 Google 的 API 10 (2.3.3) 上运行 xamarin 的 map 演示?我正在尝试使用 Monodroid 提供的 google maps api 运行 map 演示应用程序但它不起作用,它总是出现 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"
/>
这是我对 list 的许可:
<?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不是真实的。
最佳答案
我正在使用 monodroid 并且我的 map 可以正常工作.. 你正在运行演示吗?您是否已注册 debug.kestore 并开始获取 google map API key ?这是我在尝试让它工作时的一些笔记
Steps to obtain google map API key
=>(注意:Debug.keystore 存储在您的 Xamarin 文件夹中,与那些 java 应用程序不同)
- 安装谷歌公司SDK
- 获取签名 key 指纹
- 获取 map API key
- 在应用中使用 map API key
之后,要显示 map ,请使用
<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,不知何故只有带指南针的那个适合我。但只需像他们那样制作一个简单的 map 应用程序,两种方法(将 API key 放入布局文件或代码中)都可以工作。
编辑:
对于权限,将这些放在应用程序标签之外:
<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)]
对我来说,我只是像这样在布局中加载 map :
<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);
...
}
编辑:
只是注释了一些部分以使您的代码正常工作:
注意:
我假设传感器和 RotateView 有问题,因为我无法让它以那种方式工作。如果您使用 RotateView 并动态地将 mapview 添加到 linearLayout,它将起作用。现在,如果您还没有在您的应用中显示 map ,可以通过以下方式显示它
我将 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; } } }
关于c# - Monodroid 上的谷歌地图,Mac 上的错误编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9066014/