在Xamarin Mono For Android的开发中,如果要使用第三方的jar,就必须进行绑定。通过创建Java Bindings Library项目来自动生成C#到java的代码映射代码,最终产生一个dll程序集,我们调用这个程序集中的代码就可以调用jar中对应的代码。
++++++++++++++++++++++++++++++++++++++++++++++++
Xamarin Mono 移动跨平台开发群 230865920
欢迎大家进来交流
++++++++++++++++++++++++++++++++++++++++++++++++
百度地图官方Android SDK下载地址:http://developer.baidu.com/map/sdkandev-download.htm
目前最新版是 Android SDKv2.1.3,
本人下文我会同时提供Android SDKv2.1.2和Android SDKv2.1.3两个版本对应的Mono For Android Bindings下载
本bindings功能完整,与他人绑定的残缺不全版本不一样,解决了以下这些问题
2.1.2版本绑定时的警告
1>------ 已启动全部重新生成: 项目: BMap4MonoAndroid.BMapSDKBinding, 配置: Debug Any CPU ------
1>BINDINGSGENERATOR : warning BG8102: Class Com.Baidu.Mapapi.Map.Overlay has unknown base type com.baidu.platform.comapi.map.u
1>BINDINGSGENERATOR : warning BG8103: Class Com.Baidu.Mapapi.Map.GraphicsOverlay has invalid base type com.baidu.mapapi.map.Overlay
1>BINDINGSGENERATOR : warning BG8103: Class Com.Baidu.Mapapi.Map.ItemizedOverlay has invalid base type com.baidu.mapapi.map.Overlay
1>BINDINGSGENERATOR : warning BG8701: Invalid return type java.util.List<com.baidu.mapapi.map.Overlay>
1>BINDINGSGENERATOR : warning BG8103: Class Com.Baidu.Mapapi.Map.MyLocationOverlay has invalid base type com.baidu.mapapi.map.Overlay
1>BINDINGSGENERATOR : warning BG8103: Class Com.Baidu.Mapapi.Map.PoiOverlay has invalid base type com.baidu.mapapi.map.Overlay
1>BINDINGSGENERATOR : warning BG8103: Class Com.Baidu.Mapapi.Map.PopupOverlay has invalid base type com.baidu.mapapi.map.Overlay
1>BINDINGSGENERATOR : warning BG8103: Class Com.Baidu.Mapapi.Map.RouteOverlay has invalid base type com.baidu.mapapi.map.ItemizedOverlay
1>BINDINGSGENERATOR : warning BG8103: Class Com.Baidu.Mapapi.Map.TextOverlay has invalid base type com.baidu.mapapi.map.Overlay
1>BINDINGSGENERATOR : warning BG8103: Class Com.Baidu.Mapapi.Map.TransitOverlay has invalid base type com.baidu.mapapi.map.ItemizedOverlay
1>BINDINGSGENERATOR : warning BG8C00: For type Com.Baidu.Mapapi.Search.PlaceCaterActivity, base interface com.baidu.mapapi.search.a.a does not exist.
1>BINDINGSGENERATOR : warning BG8700: Unknown return type com.baidu.vi.d
1>BINDINGSGENERATOR : warning BG8C00: For type Com.Baidu.Mapapi.Search.PlaceCaterActivity, base interface com.baidu.mapapi.search.a.a does not exist.
1>BINDINGSGENERATOR : warning BG8401: Skipping Com.Baidu.Mapapi.Search.MKSearch.PoiDetailSearch, due to a duplicate field, method or nested type name
1>D:\Development\BMap4MonoAndroid\BMap4MonoAndroid.BMapSDKBinding\obj\Debug\generated\src\Com.Baidu.Mapapi.Map.MapView.cs(13,24,13,36): warning CS0108: “Com.Baidu.Mapapi.Map.MapView.LayoutParams”隐藏了继承的成员“Android.Views.ViewGroup.LayoutParams”。如果是有意隐藏,请使用关键字 new。
1>D:\Development\BMap4MonoAndroid\BMap4MonoAndroid.BMapSDKBinding\obj\Debug\generated\src\Com.Baidu.Mapapi.Map.MapView.cs(826,36,826,55): warning CS0618: “Com.Baidu.Mapapi.Map.MapView.ZoomControls”已过时:“deprecated”
1> BMap4MonoAndroid.BMapSDKBinding -> D:\Development\BMap4MonoAndroid\BMap4MonoAndroid.BMapSDKBinding\bin\Debug\BMap4MonoAndroid.v2.1.2.dll
========== 全部重新生成: 成功 1 个,失败 0 个,跳过 0 个 ==========
2.1.3版本绑定时的警告
1>------ 已启动全部重新生成: 项目: BMap4MonoAndroid.BMapSDKBinding_2_1_3, 配置: Debug Any CPU ------
1>BINDINGSGENERATOR : warning BG8102: Class Com.Baidu.Mapapi.Map.Overlay has unknown base type com.baidu.platform.comapi.map.v
1>BINDINGSGENERATOR : warning BG8103: Class Com.Baidu.Mapapi.Map.GraphicsOverlay has invalid base type com.baidu.mapapi.map.Overlay
1>BINDINGSGENERATOR : warning BG8103: Class Com.Baidu.Mapapi.Map.ItemizedOverlay has invalid base type com.baidu.mapapi.map.Overlay
1>BINDINGSGENERATOR : warning BG8701: Invalid return type java.util.List
1>BINDINGSGENERATOR : warning BG8103: Class Com.Baidu.Mapapi.Map.MyLocationOverlay has invalid base type com.baidu.mapapi.map.Overlay
1>BINDINGSGENERATOR : warning BG8103: Class Com.Baidu.Mapapi.Map.PoiOverlay has invalid base type com.baidu.mapapi.map.Overlay
1>BINDINGSGENERATOR : warning BG8103: Class Com.Baidu.Mapapi.Map.PopupOverlay has invalid base type com.baidu.mapapi.map.Overlay
1>BINDINGSGENERATOR : warning BG8103: Class Com.Baidu.Mapapi.Map.RouteOverlay has invalid base type com.baidu.mapapi.map.ItemizedOverlay
1>BINDINGSGENERATOR : warning BG8103: Class Com.Baidu.Mapapi.Map.TextOverlay has invalid base type com.baidu.mapapi.map.Overlay
1>BINDINGSGENERATOR : warning BG8103: Class Com.Baidu.Mapapi.Map.TransitOverlay has invalid base type com.baidu.mapapi.map.ItemizedOverlay
1>BINDINGSGENERATOR : warning BG8C00: For type Com.Baidu.Mapapi.Search.PlaceCaterActivity, base interface com.baidu.mapapi.search.a.a does not exist.
1>BINDINGSGENERATOR : warning BG8102: Class Com.Baidu.Platform.Comapi.Map.A has unknown base type com.baidu.platform.comapi.map.d
1>BINDINGSGENERATOR : warning BG8700: Unknown return type com.baidu.vi.d
1>BINDINGSGENERATOR : warning BG8C00: For type Com.Baidu.Mapapi.Search.PlaceCaterActivity, base interface com.baidu.mapapi.search.a.a does not exist.
1>BINDINGSGENERATOR : warning BG8401: Skipping Com.Baidu.Mapapi.Search.MKSearch.PoiDetailSearch, due to a duplicate field, method or nested type name
1>D:\Development\BMap4MonoAndroid\BMap4MonoAndroid.BMapSDKBinding_2_1_3\obj\Debug\generated\src\Com.Baidu.Mapapi.Map.MapView.cs(13,24,13,36): warning CS0108: “Com.Baidu.Mapapi.Map.MapView.LayoutParams”隐藏了继承的成员“Android.Views.ViewGroup.LayoutParams”。如果是有意隐藏,请使用关键字 new。
1>D:\Development\BMap4MonoAndroid\BMap4MonoAndroid.BMapSDKBinding_2_1_3\obj\Debug\generated\src\Com.Baidu.Mapapi.Map.MapView.cs(826,36,826,55): warning CS0618: “Com.Baidu.Mapapi.Map.MapView.ZoomControls”已过时:“deprecated”
1> BMap4MonoAndroid.BMapSDKBinding_2_1_3 -> D:\Development\BMap4MonoAndroid\BMap4MonoAndroid.BMapSDKBinding_2_1_3\bin\Debug\BMap4MonoAndroid.v2.1.3.dll
========== 全部重新生成: 成功 1 个,失败 0 个,跳过 0 个 ==========
本绑定已经解决以上这些问题
绑定好的dll下载
BMap4MonoAndroid.v2.1.3.rar BMap4MonoAndroid.v2.1.2.rar
请注意,百度地图Android SDK不支持x86平台,使用的时候请注意。
如何使用绑定好的dll呢?
1、创建AndroidApplication项目,项目名称为BMap4MonoAndroid.App
2、下载BMap4MonoAndroid.v2.1.3.rar或BMap4MonoAndroid.v2.1.2.rar并解压缩
3、BMap4MonoAndroid.App项目添加对BMap4MonoAndroid.v2.1.3.dll或BMap4MonoAndroid.v2.1.2.dll的引用
4、将Libs目录复制进BMap4MonoAndroid.App项目的根目录,展开目录Libs->armeabi-v7a,选中目录下的全部.so文件,在属性窗口中把生成操作设置为AndroidNativeLibrary
5、在项目目录上点右键,选择属性菜单进入项目属性设置界面,切换到Android Manifest选项卡,给应用分类一下权限
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_WIFI_STATE
android.permission.READ_PHONE_STATE
android.permission.ACCESS_FINE_LOCATION
Application Name处填入BMap4MonoAndroid
package Name处填入com.bmap.monodroid
保存修改
6、打开Activity1.cs文件,在OnCreate方法下输入如下代码
base.OnCreate(bundle);
var mBMapMan = new BMapManager(Application);
//mBMapMan.Init("B1EB2D5670D2335541E3C80503DB46C18BD5CDB8", null);//v 2.1.2版测试key
mBMapMan.Init("19085348c8c35652918dcd264aacd915", null); //v 2.1.3版测试key
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main); // Get our button from the layout resource,
// and attach an event to it
var view = FindViewById<MapView>(Resource.Id.bmapsView); view.SetBuiltInZoomControls(true); view.Traffic = true; MapController mMapController = view.Controller;
// 得到mMapView的控制权,可以用它控制和驱动平移和缩放
var point = new GeoPoint((int) (39.915*1E6), (int) (116.404*1E6));
//用给定的经纬度构造一个GeoPoint,单位是微度 (度 * 1E6)
mMapController.SetCenter(point); //设置地图中心点
mMapController.SetZoom(); //设置地图zoom级别 //++++++++++++++++++++++++
// //pop demo
var pop = new PopupOverlay(view, new PopupClickListener());
///** 准备pop弹窗资源,根据实际情况更改
// * 弹出包含三张图片的窗口,可以传入三张图片、两张图片、一张图片。
// * 弹出的窗口,会根据图片的传入顺序,组合成一张图片显示.
// * 点击到不同的图片上时,回调函数会返回当前点击到的图片索引index
// */
var bmps = new Bitmap[];
try
{
bmps[] = BitmapFactory.DecodeStream(Assets.Open("Icon.png"));
bmps[] = BitmapFactory.DecodeStream(Assets.Open("Icon.png"));
bmps[] = BitmapFactory.DecodeStream(Assets.Open("Icon.png"));
}
catch (IOException e)
{
//e.printStackTrace();
}
//弹窗弹出位置
var ptTAM = new GeoPoint((int) (39.915*1E6), (int) (116.404*1E6));
//弹出pop,隐藏pop
pop.ShowPopup(bmps, ptTAM, ); //Com.Baidu.Platform.Comapi.Map.Overlay
创建一个新类PopupClickListener
public class PopupClickListener : IPopupClickListener
{
public void Dispose()
{
//throw new NotImplementedException(); } public IntPtr Handle { get; private set; } public void OnClickedPopup(int p0)
{ }
}
好了,可以运行了,运行效果如下
Mono For Android百度地图demo应用下载
<完>
Category: MonoDriod 标签:BaiduMap Binding, binding jar, mono for android, 百度地图SDK
转载自http://mdev.iquan.net/mono-for-android-baidumap-sdk2-1-2-2-1-3-binding/