<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="50dip" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="在" > </TextView> <EditText android:id="@+id/city" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="北京" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="市内找" > </TextView> <AutoCompleteTextView android:id="@+id/searchkey" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0.88" android:text="餐厅" /> </LinearLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="50dip" android:orientation="horizontal" > <Button android:id="@+id/search" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="12" android:background="@drawable/button_style" android:padding="10dip" android:text="开始" /> <Button android:id="@+id/map_next_data" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="12" android:background="@drawable/button_style" android:padding="10dip" android:text="下一组数据" /> </LinearLayout> <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.baidu.mapapi.map.TextureMapFragment" /> </LinearLayout>
using Com.Baidu.Mapapi.Map;
using Com.Baidu.Mapapi.Model;
using System.Collections.Generic;
namespace BdMapV371Demos.SrcOverlayUtil
{
/// <summary>
/// 提供一个能够显示和管理多个Overlay的基类。
/// 将覆盖物点击事件传递给OverlayManager后,OverlayManager才能响应点击事件。
/// 在MarkerClick事件中处理Marker点击事件。
/// </summary>
public abstract class OverlayManager : Java.Lang.Object, BaiduMap.IOnMarkerClickListener, BaiduMap.IOnPolylineClickListener
{
BaiduMap mBaiduMap = null;
private List<OverlayOptions> mOverlayOptionList = null;
protected List<Overlay> mOverlayList = null;
public OverlayManager(BaiduMap baiduMap)
{
mBaiduMap = baiduMap;
mBaiduMap.SetOnMarkerClickListener(this);
if (mOverlayOptionList == null)
{
mOverlayOptionList = new List<OverlayOptions>();
}
if (mOverlayList == null)
{
mOverlayList = new List<Overlay>();
}
}
/// <summary>
/// 重写此方法设置要管理的Overlay列表
/// </summary>
/// <returns></returns>
public abstract List<OverlayOptions> GetOverlayOptions();
/// <summary>
/// 将所有Overlay 添加到地图上
/// </summary>
public void AddToMap()
{
if (mBaiduMap == null)
{
return;
}
RemoveFromMap();
List<OverlayOptions> overlayOptions = GetOverlayOptions();
if (overlayOptions != null)
{
mOverlayOptionList.AddRange(GetOverlayOptions());
}
foreach (OverlayOptions option in mOverlayOptionList)
{
mOverlayList.Add(mBaiduMap.AddOverlay(option));
}
}
/// <summary>
/// 将所有Overlay从地图上消除
/// </summary>
public void RemoveFromMap()
{
if (mBaiduMap == null)
{
return;
}
foreach (Overlay marker in mOverlayList)
{
marker.Remove();
}
mOverlayOptionList.Clear();
mOverlayList.Clear();
}
/// <summary>
/// 缩放地图,使所有Overlay都在合适的视野内
/// 注: 该方法只对Marker类型的overlay有效
/// </summary>
public void ZoomToSpan()
{
if (mBaiduMap == null)
{
return;
}
if (mOverlayList.Count > 0)
{
LatLngBounds.Builder builder = new LatLngBounds.Builder();
foreach (Overlay overlay in mOverlayList)
{
// polyline 中的点可能太多,只按marker缩放
if (overlay is Marker)
{
builder.Include(((Marker)overlay).Position);
}
}
mBaiduMap.SetMapStatus(MapStatusUpdateFactory
.NewLatLngBounds(builder.Build()));
}
}
public virtual bool OnMarkerClick(Marker marker)
{
return false;
}
public virtual bool OnPolylineClick(Polyline polyline)
{
return false;
}
}
}
using Android.OS;
using Android.Widget;
using Com.Baidu.Mapapi;
using Com.Baidu.Mapapi.Map;
using Com.Baidu.Mapapi.Search.Poi;
using System.Collections.Generic;
namespace BdMapV371Demos.SrcOverlayUtil
{
/// <summary>
/// 显示一条公交详情结果的Overlay,继承自该类的子类可显示其他类型的Overlay
/// </summary>
public class PoiOverlay : OverlayManager
{
private static readonly int MaxPoiSize = 10;
private PoiResult mPoiResult = null;
public PoiOverlay(BaiduMap baiduMap) : base(baiduMap)
{
}
/// <summary>
/// 设置POI数据
/// </summary>
/// <param name="poiResult">POI结果数据</param>
public void SetData(PoiResult poiResult)
{
this.mPoiResult = poiResult;
}
public override List<OverlayOptions> GetOverlayOptions()
{
if (mPoiResult == null || mPoiResult.AllPoi == null)
{
return null;
}
List<OverlayOptions> markerList = new List<OverlayOptions>();
int markerSize = 0;
for (int i = 0; i < mPoiResult.AllPoi.Count && markerSize < MaxPoiSize; i++)
{
if (mPoiResult.AllPoi[i].Location == null)
{
continue;
}
markerSize++;
Bundle bundle = new Bundle();
bundle.PutInt("index", i);
markerList.Add(new MarkerOptions()
.InvokeIcon(BitmapDescriptorFactory.FromAssetWithDpi("Icon_mark"
+ markerSize + ".png")).InvokeExtraInfo(bundle)
.InvokePosition(mPoiResult.AllPoi[i].Location));
}
return markerList;
}
/// <summary>
/// 获取该 PoiOverlay 的 poi数据
/// </summary>
public PoiResult GetPoiResult()
{
return mPoiResult;
}
/// <summary>
/// 重写此方法可改变默认点击行为
/// </summary>
/// <param name="i">被点击的poi在PoiResult.AllPoi中的索引</param>
/// <returns></returns>
public virtual bool OnPoiClick(int i)
{
if (mPoiResult.AllPoi != null && mPoiResult.AllPoi[i] != null)
{
Toast.MakeText(BMapManager.Context,
mPoiResult.AllPoi[i].Name, ToastLength.Long).Show();
}
return false;
}
public override bool OnMarkerClick(Marker marker)
{
if (!mOverlayList.Contains(marker))
{
return false;
}
if (marker.ExtraInfo != null)
{
return OnPoiClick(marker.ExtraInfo.GetInt("index"));
}
return false;
}
public override bool OnPolylineClick(Polyline polyline)
{
return false;
}
}
}
using Android.App;
using Android.Content.PM;
using Android.OS;
using Android.Support.V4.App;
using Android.Widget;
using BdMapV371Demos.SrcOverlayUtil;
using Com.Baidu.Mapapi.Map;
using Com.Baidu.Mapapi.Search.Core;
using Com.Baidu.Mapapi.Search.Poi;
using Com.Baidu.Mapapi.Search.Sug;
namespace BdMapV371Demos.SrcSdkDemos
{
/// <summary>
/// 演示poi搜索功能
/// </summary>
[Activity(Label = "@string/demo_name_poi",
ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden,
ScreenOrientation = ScreenOrientation.Sensor)]
public class Demo12PoiSearch : FragmentActivity
{
private PoiSearch mPoiSearch = null;
private SuggestionSearch mSuggestionSearch = null;
private BaiduMap mBaiduMap = null;
// 搜索关键字输入窗口
private AutoCompleteTextView keyWorldsView = null;
private ArrayAdapter<string> sugAdapter = null;
private int load_Index = 0;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.demo12_poisearch);
// 初始化搜索模块,注册搜索事件监听
mPoiSearch = PoiSearch.NewInstance();
mPoiSearch.GetPoiResult += (s, e) =>
{
var result = e.P0;
if (result == null
|| result.Error == SearchResult.ERRORNO.ResultNotFound)
{
return;
}
if (result.Error == SearchResult.ERRORNO.NoError)
{
mBaiduMap.Clear();
PoiOverlay overlay = new MyPoiOverlay(this, mBaiduMap);
mBaiduMap.SetOnMarkerClickListener(overlay);
overlay.SetData(result);
overlay.AddToMap();
overlay.ZoomToSpan();
return;
}
if (result.Error == SearchResult.ERRORNO.AmbiguousKeyword)
{
// 当输入关键字在本市没有找到,但在其他城市找到时,返回包含该关键字信息的城市列表
string strInfo = "在";
foreach (CityInfo cityInfo in result.SuggestCityList)
{
strInfo += cityInfo.City;
strInfo += ",";
}
strInfo += "找到结果";
Toast.MakeText(this, strInfo, ToastLength.Long)
.Show();
}
};
mPoiSearch.GetPoiDetailResult += (s, e) =>
{
var result = e.P0;
if (result.Error != SearchResult.ERRORNO.NoError)
{
Toast.MakeText(this, "抱歉,未找到结果", ToastLength.Short).Show();
}
else
{
Toast.MakeText(this, "成功,查看详情页面", ToastLength.Short).Show();
}
};
mSuggestionSearch = SuggestionSearch.NewInstance();
mSuggestionSearch.GetSuggestionResult += (s, e) =>
{
var res = e.P0;
if (res == null || res.AllSuggestions == null) return;
sugAdapter.Clear();
foreach (SuggestionResult.SuggestionInfo info in res.AllSuggestions)
{
if (info.Key != null) sugAdapter.Add(info.Key);
}
sugAdapter.NotifyDataSetChanged();
};
keyWorldsView = FindViewById<AutoCompleteTextView>(Resource.Id.searchkey);
sugAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleDropDownItem1Line);
keyWorldsView.Adapter = sugAdapter;
TextureMapFragment map1 = FragmentManager.FindFragmentById<TextureMapFragment>(Resource.Id.map);
mBaiduMap = map1.BaiduMap;
// 当输入关键字变化时,动态更新建议列表
keyWorldsView.AfterTextChanged += (sender, e) => { };
keyWorldsView.BeforeTextChanged += (sender, e) => { };
keyWorldsView.TextChanged += (sender, e) =>
{
string s = e.Text.ToString();
if (s.Length <= 0) return;
string city = (FindViewById<EditText>(Resource.Id.city)).Text;
// 使用建议搜索服务获取建议列表,结果在onSuggestionResult()中更新
mSuggestionSearch.RequestSuggestion(
new SuggestionSearchOption().Keyword(s).City(city));
};
Button btnSearch = FindViewById<Button>(Resource.Id.search);
btnSearch.Click += delegate
{
SearchButtonProcess();
};
Button btnNext = FindViewById<Button>(Resource.Id.map_next_data);
btnNext.Click += delegate
{
load_Index++;
SearchButtonProcess();
};
}
protected override void OnPause()
{
base.OnPause();
}
protected override void OnResume()
{
base.OnResume();
}
protected override void OnDestroy()
{
mPoiSearch.Destroy();
mSuggestionSearch.Destroy();
base.OnDestroy();
}
protected override void OnSaveInstanceState(Bundle outState)
{
base.OnSaveInstanceState(outState);
}
protected override void OnRestoreInstanceState(Bundle savedInstanceState)
{
base.OnRestoreInstanceState(savedInstanceState);
}
public void SearchButtonProcess()
{
EditText editCity = FindViewById<EditText>(Resource.Id.city);
EditText editSearchKey = FindViewById<EditText>(Resource.Id.searchkey);
mPoiSearch.SearchInCity(new PoiCitySearchOption()
.City(editCity.Text)
.Keyword(editSearchKey.Text)
.PageNum(load_Index));
}
private class MyPoiOverlay : PoiOverlay
{
Demo12PoiSearch poiSearchDemo;
public MyPoiOverlay(Demo12PoiSearch poiSearchDemo, BaiduMap baiduMap) :
base(baiduMap)
{
this.poiSearchDemo = poiSearchDemo;
}
public override bool OnPoiClick(int index)
{
base.OnPoiClick(index);
PoiInfo poi = GetPoiResult().AllPoi[index];
if (poi.HasCaterDetails)
{
poiSearchDemo.mPoiSearch.SearchPoiDetail(
new PoiDetailSearchOption().PoiUid(poi.Uid));
}
return true;
}
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有