download Baidu map First Http://lbsyun.baidu.com/sdk/download?selected=mapsdk_basicmap,mapsdk_searchfunction,mapsdk_ Lbscloudsearch,mapsdk_calculationtool
Create a new Bindingslibrary project and add the newly downloaded Baidulbs_android.jar to the project's jars folder, changing the properties of the Baidulbs_android.jar " Build Action " property is Embeddedjar
Build some projects, if you encounter such an error:
versioninfo ": member names cannot be the same as their enclosing types
Open the project in the Transforms of the Metadate.xml , in <metadata> Add the following code to the node
<attr path= "/api/package[@name = ' Com.baidu.mapapi ']/class[@name = ' versioninfo ']/field[@name = ' version_info ']" Name= "Name" >VersionInfos</attr>
because in C # cannot define class members with the same class name (except constructors)
in your project, create a Libs folder, put the downloaded Baidu map package in the . so file is added and set to the property on the androidnativelibrary
650) this.width=650; "title=" Xamainandroidbiadu001.png "src=" http://s3.51cto.com/wyfs02/M02/75/0B/ Wkiom1yxcmmhmxehaannwxpvrg4488.jpg "alt=" Wkiom1yxcmmhmxehaannwxpvrg4488.jpg "/>
Add permissions and settings Baidu maps access App Key
<application android:label= "Baidumapdemo" android:icon= "@drawable/icon" > <meta-data android : Name= "Com.baidu.lbsapi.API_KEY" android:value= "This need to register Baidu open platform to apply for Android KEY" /> </application> < Uses-permission android:name= "Android.permission.ACCESS_MOCK_LOCATION" /> <uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE" / > <uses-permission android:name= " Android.permission.ACCESS_WIFI_STATE " /> < Uses-permission android:name= "Android.permission.INTERNET" /> <!-- This permission is used to get access to WiFi and WiFi information is used toLine network Location--> <uses-permission android:name= " Android.permission.CHANGE_WIFI_STATE "></uses-permission> <!-- To read the current status of the phone--> <uses-permission Android:name= "Android.permission.READ_PHONE_STATE" ></uses-permission> <uses-permission android:name= "Android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name= " Android.permission.ACCESS_COARSE_LOCATION /> Add a map control to a layout file (Note case:) < Com.baidu.mapapi.map.mapview android:id= "@+id/bmapView" android:layout_width= "Fill_parent" android:layout_height= "Fill_parent" &nbSp; android:clickable= "true" />
C # The code is as follows
Using android.app;using android.content;using android.runtime;using android.widget;using Android.OS;using Com.Baidu.Mapapi.Map;using Com.Baidu.Mapapi;using Android.Locations; Using com.baidu.mapapi.model; namespace baidumapdemo{ [activity (Label = "Baidumapdemo", mainlauncher = true, icon = "@drawable/icon")] public class mainactivity : activity, ilocationlistener// Positioning interface for Android { LocationManager locmgr; mapview mmapview ; BaiduMap mBaiduMap ; Protected override void oncreate (Bundle bundle) { base. OnCreate (bundle); //map, note the location, Before the Setcontentview Sdkinitializer.initialize (Application.context); setcontentview (Resource.Layout.Main); mMapView = FindViewById<MapView> (Resource.Id.bmapView); mBaiduMap = mMapView.Map; //General Map mBaiduMap.MapType = BaiduMap.MapTypeNormal; } &nbSp; protected override void onresume () { base. Onresume (); locmgr = Getsystemservice (Context.locationservice) as LocationManager; criteria locationcriteria = new criteria () ; locationcriteria.accuracy = Accuracy.Coarse; locationcriteria.powerrequirement = power.medium; locationcriteria.altituderequired = false;//Altitude locationcriteria.bearingrequired = false;//Azimuth/Direction locationcriteria.speedrequired = false;//Speed locationcriteria.costallowed = true;//cost var locationprovider = locmgr.getbestprovider ( Locationcriteria, true); if (locationprovider != null) { locmgr.requestlocationupdates (Locationprovider, 2000, 1, this); } else { toast.maketext (this, "the network provider does not exist or is not enabled! ", Toastlength.long). Show (); } } protected override void onstart () { base. OnStart (); } Protected override void onstop () { base. OnStop (); &nbSp; } protected override void onpause () { base. OnPause (); locmgr.removeupdates (this); } /// <summary> /// implementation of Ilocationlistener methods, position change /// </summary> /// <param name= "Location" ></param> public void onlocationchanged (location location) { var point&NBSP;=&NBSP;NEW&NBSP;LATLNG (location. Latitude, location. Longitude) //make the map move to the current location MapStatus mMapStatus = new Mapstatus.builder () . Target (point) . Zoom (&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP); Build (); //defines the Mapstatusupdate object, To describe the changes that will occur in the map state Mapstatusupdate mmapstatusupdate = mapstatusupdatefactory.newmapstatus (MMapStatus); //Change Map Status &NBsp; mbaidumap.setmapstatus ( Mmapstatusupdate); // Create current position marker icon bitmapdescriptor bitmap = bitmapdescriptorfactory . Fromresource (Resource.Drawable.icon_gcoding); //build markeroption for adding marker on the map overlayoptions option = new markeroptions () . Invokeposition (point) . Invokeicon (bitmap); //add marker to the map and display mbaidumap.addoverlay (option); } /// < summary> /// implementation of Ilocationlistener methods /// </summary> /// <param name= "Provider" ></param> public void onproviderdisabled (String provider) { } /// <summary> /// Implementation IlocaMethods /// </summary> in Tionlistener /// <param name= "Provider" ></param> public void onproviderenabled (String provider) { } /// <summary> /// Implementing Ilocationlistener Methods /// </summary> /// <param Name= "Provider" ></param> /// <param name= "Status" ></param> /// <param name= "extras "></param> public void onstatuschanged (string provider, [ Generatedenum] availability status, bundle extras) { } }}
This article is from the "Gui Suewei" blog, make sure to keep this source http://axzxs.blog.51cto.com/730810/1707541
Xamarin Snippets 4--xamarin.android Baidu map bindings