【Android】3.22 示例22--LBS云检索功能
分類:C#、Android、VS2015、百度地圖應用; 創建日期:2016-02-04
簡介:介紹如何使用LBS.云檢索用戶自有數據。
詳述:
(1)LBS.云是百度地圖針對LBS開發者推出的平臺級服務;
(2)提供海量位置數據存儲、檢索、展示一體化解決方案;
(3)該服務對開發者免費開放;
(4)Demo中放入了測試用ak,開發者若使用自己的數據,請更換為自己的ak;
(5)LBS.云檢索使用方法請參考開發指南“LBS云服務”部分;
(6)詳細了解LBS.云,歡迎訪問:http://developer.baidu.com/map/lbs-cloud.htm
(7)申請ak及管理數據等問題,歡迎訪問LBS開放平臺官網:http://lbsyun.baidu.com/
一、運行截圖
本示例運行截圖如下:
二、設計步驟
1、添加demo22_cloud_search.xml文件
在layout文件夾下添加該文件,代碼不再列出。
2、添加Demo22CloudSearch.cs文件
在SrcSdkDemos文件夾下添加該文件,然后將代碼改為下面的內容:
using Android.App; using Android.Content; using Android.OS; using Android.Widget; namespace BdMapV371Demos.SrcSdkDemos {[Activity(Label = "@string/title_activity_cloud_search_demo")]public class Demo22CloudSearch : Activity{protected override void OnCreate(Bundle savedInstanceState){base.OnCreate(savedInstanceState);SetContentView(Resource.Layout.demo22_cloud_search);FindViewById<Button>(Resource.Id.startCloudSearchDemo).Click += delegate{Intent intent = new Intent();intent.SetClass(this, typeof(Demo22CloudSearchActivity));StartActivity(intent);};}} }3、添加Demo22CloudSearchActivity.cs文件
在SrcSdkDemos文件夾下添加該文件,然后將代碼改為下面的內容:
using Android.App; using Android.Content.PM; using Android.OS; using Android.Util; using Android.Widget; using Com.Baidu.Mapapi.Cloud; using Com.Baidu.Mapapi.Map; using Com.Baidu.Mapapi.Model; namespace BdMapV371Demos.SrcSdkDemos {[Activity(Label = "@string/demo_name_cloud",ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden,ScreenOrientation = ScreenOrientation.Sensor)]public class Demo22CloudSearchActivity : Activity, ICloudListener{private static readonly string LTAG = nameof(Demo22CloudSearchActivity);private TextureMapView mMapView;private BaiduMap mBaiduMap;protected override void OnCreate(Bundle icicle){base.OnCreate(icicle);SetContentView(Resource.Layout.demo22_lbssearch);CloudManager.Instance.Init(this);mMapView = FindViewById<TextureMapView>(Resource.Id.bmapView);mBaiduMap = mMapView.Map;FindViewById(Resource.Id.regionSearch).Click += delegate{LocalSearchInfo info = new LocalSearchInfo();info.Ak = "B266f735e43ab207ec152deff44fec8b";info.GeoTableId = 31869;info.Tags = "";info.Q = "天安門";info.Region = "北京市";CloudManager.Instance.LocalSearch(info);};FindViewById(Resource.Id.regionSearch).Click += delegate{LocalSearchInfo info = new LocalSearchInfo();info.Ak = "B266f735e43ab207ec152deff44fec8b";info.GeoTableId = 31869;info.Tags = "";info.Q = "天安門";info.Region = "北京市";CloudManager.Instance.LocalSearch(info);};FindViewById(Resource.Id.nearbySearch).Click += delegate{NearbySearchInfo info = new NearbySearchInfo();info.Ak = "D9ace96891048231e8777291cda45ca0";info.GeoTableId = 32038;info.Radius = 30000;info.Location = "116.403689,39.914957";CloudManager.Instance.NearbySearch(info);};FindViewById(Resource.Id.boundsSearch).Click += delegate{BoundSearchInfo info = new BoundSearchInfo();info.Ak = "B266f735e43ab207ec152deff44fec8b";info.GeoTableId = 31869;info.Q = "天安門";info.Bound = "116.401663,39.913961;116.406529,39.917396";CloudManager.Instance.BoundSearch(info);};FindViewById(Resource.Id.detailsSearch).Click += delegate{DetailSearchInfo info = new DetailSearchInfo();info.Ak = "B266f735e43ab207ec152deff44fec8b";info.GeoTableId = 31869;info.Uid = 18622266;CloudManager.Instance.DetailSearch(info);};}protected override void OnDestroy(){base.OnDestroy();mMapView.OnDestroy();CloudManager.Instance.Destroy();}protected override void OnPause(){base.OnPause();mMapView.OnPause();}protected override void OnResume(){base.OnResume();mMapView.OnResume();}public void OnGetDetailSearchResult(DetailSearchResult result, int error){if (result != null){if (result.PoiInfo != null){Toast.MakeText(this, result.PoiInfo.Title, ToastLength.Short).Show();}else{Toast.MakeText(this, "status:" + result.Status, ToastLength.Short).Show();}}}public void OnGetSearchResult(CloudSearchResult result, int error){if (result != null && result.PoiList != null && result.PoiList.Count > 0){Log.Debug(LTAG, "onGetSearchResult, result length: " + result.PoiList.Count);mBaiduMap.Clear();BitmapDescriptor bd = BitmapDescriptorFactory.FromResource(Resource.Drawable.icon_gcoding);LatLng ll;LatLngBounds.Builder builder = new LatLngBounds.Builder();foreach (CloudPoiInfo info in result.PoiList){ll = new LatLng(info.Latitude, info.Longitude);OverlayOptions oo = new MarkerOptions().InvokeIcon(bd).InvokePosition(ll);mBaiduMap.AddOverlay(oo);builder.Include(ll);}LatLngBounds bounds = builder.Build();MapStatusUpdate u = MapStatusUpdateFactory.NewLatLngBounds(bounds);mBaiduMap.AnimateMapStatus(u);}}} }4、修改MainActivity.cs文件
在MainActivity.cs文件的demos字段定義中,去掉【示例22】下面的注釋。
運行觀察效果。
轉載于:https://www.cnblogs.com/rainmj/p/5181843.html
總結
以上是生活随笔為你收集整理的【Android】3.22 示例22--LBS云检索功能的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 有一天人人都会变成程序猿
- 下一篇: [Hadoop] Hadoop学习历程