百度SDK提供了查询公交路线的功能,并且可以浏览路线要经过的每一个站,百度Demo代码如下:
Activity:
package com.home; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.baidu.mapapi.map.MKMapTouchListener; import com.baidu.mapapi.map.MapView; import com.baidu.mapapi.map.PopupClickListener; import com.baidu.mapapi.map.PopupOverlay; import com.baidu.mapapi.map.RouteOverlay; import com.baidu.mapapi.search.MKAddrInfo; import com.baidu.mapapi.search.MKBusLineResult; import com.baidu.mapapi.search.MKDrivingRouteResult; import com.baidu.mapapi.search.MKPoiInfo; import com.baidu.mapapi.search.MKPoiResult; import com.baidu.mapapi.search.MKRoute; import com.baidu.mapapi.search.MKSearch; import com.baidu.mapapi.search.MKSearchListener; import com.baidu.mapapi.search.MKShareUrlResult; import com.baidu.mapapi.search.MKSuggestionResult; import com.baidu.mapapi.search.MKTransitRouteResult; import com.baidu.mapapi.search.MKWalkingRouteResult; import com.baidu.platform.comapi.basestruct.GeoPoint; /** * 此demo用来展示如何进行公交线路详情检索,并使用RouteOverlay在地图上绘制 同时展示如何浏览路线节点并弹出泡泡 * */ public class BusLineSearchActivity extends Activity { // UI相关 Button mBtnSearch = null; Button mBtnNextLine = null; // 浏览路线节点相关 Button mBtnPre = null;// 上一个节点 Button mBtnNext = null;// 下一个节点 int nodeIndex = -2;// 节点索引,供浏览节点时使用 MKRoute route = null;// 保存驾车/步行路线数据的变量,供浏览节点时使用 private PopupOverlay pop = null;// 弹出泡泡图层,浏览节点时使用 private TextView popupText = null;// 泡泡view private View viewCache = null; private List<String> busLineIDList = null; int busLineIndex = 0; // 地图相关,使用继承MapView的MyBusLineMapView目的是重写touch事件实现泡泡处理 // 如果不处理touch事件,则无需继承,直接使用MapView即可 MapView mMapView = null; // 地图View // 搜索相关 MKSearch mSearch = null; // 搜索模块,也可去掉地图模块独立使用 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DemoApplication app = (DemoApplication) this.getApplication(); setContentView(R.layout.activity_buslinesearch); CharSequence titleLable = "公交线路查询功能"; setTitle(titleLable); // 地图初始化 mMapView = (MapView) findViewById(R.id.bmapView); mMapView.getController().enableClick(true); mMapView.getController().setZoom(12); busLineIDList = new ArrayList<String>(); // 创建 弹出泡泡图层 createPaopao(); // 地图点击事件处理 mMapView.regMapTouchListner(new MKMapTouchListener() { @Override public void onMapClick(GeoPoint point) { // 在此处理地图点击事件 // 消隐pop if (pop != null) { pop.hidePop(); } } @Override public void onMapDoubleClick(GeoPoint point) { } @Override public void onMapLongClick(GeoPoint point) { } }); // 初始化搜索模块,注册事件监听 mSearch = new MKSearch(); mSearch.init(app.mBMapManager, new MKSearchListener() { @Override public void onGetPoiDetailSearchResult(int type, int error) { } public void onGetPoiResult(MKPoiResult res, int type, int error) { // 错误号可参考MKEvent中的定义 if (error != 0 || res == null) { Toast.makeText(BusLineSearchActivity.this, "抱歉,未找到结果", Toast.LENGTH_SHORT).show(); return; } // 找到公交路线poi node MKPoiInfo curPoi = null; int totalPoiNum = res.getCurrentNumPois(); // 遍历所有poi,找到类型为公交线路的poi busLineIDList.clear(); for (int idx = 0; idx < totalPoiNum; idx++) { if (2 == res.getPoi(idx).ePoiType) { // poi类型,0:普通点,1:公交站,2:公交线路,3:地铁站,4:地铁线路 curPoi = res.getPoi(idx); // 使用poi的uid发起公交详情检索 busLineIDList.add(curPoi.uid); System.out.println(curPoi.uid); } } SearchNextBusline(); // 没有找到公交信息 if (curPoi == null) { Toast.makeText(BusLineSearchActivity.this, "抱歉,未找到结果", Toast.LENGTH_LONG).show(); return; } route = null; } public void onGetDrivingRouteResult(MKDrivingRouteResult res, int error) { } public void onGetTransitRouteResult(MKTransitRouteResult res, int error) { } public void onGetWalkingRouteResult(MKWalkingRouteResult res, int error) { } public void onGetAddrResult(MKAddrInfo res, int error) { } /** * 获取公交路线结果,展示公交线路 */ public void onGetBusDetailResult(MKBusLineResult result, int iError) { if (iError != 0 || result == null) { Toast.makeText(BusLineSearchActivity.this, "抱歉,未找到结果", Toast.LENGTH_LONG).show(); return; } RouteOverlay routeOverlay = new RouteOverlay( BusLineSearchActivity.this, mMapView); // 此处仅展示一个方案作为示例 routeOverlay.setData(result.getBusRoute()); // 清除其他图层 mMapView.getOverlays().clear(); // 添加路线图层 mMapView.getOverlays().add(routeOverlay); // 刷新地图使生效 mMapView.refresh(); // 移动地图到起点 mMapView.getController().animateTo( result.getBusRoute().getStart()); // 将路线数据保存给全局变量 route = result.getBusRoute(); // 重置路线节点索引,节点浏览时使用 nodeIndex = -1; mBtnPre.setVisibility(View.VISIBLE); mBtnNext.setVisibility(View.VISIBLE); Toast.makeText(BusLineSearchActivity.this, result.getBusName(), Toast.LENGTH_SHORT).show(); } @Override public void onGetSuggestionResult(MKSuggestionResult res, int arg1) { } @Override public void onGetShareUrlResult(MKShareUrlResult result, int type, int error) { } }); // 设定搜索按钮的响应 mBtnSearch = (Button) findViewById(R.id.search); mBtnNextLine = (Button) findViewById(R.id.nextline); mBtnPre = (Button) findViewById(R.id.pre); mBtnNext = (Button) findViewById(R.id.next); mBtnPre.setVisibility(View.INVISIBLE); mBtnNext.setVisibility(View.INVISIBLE); OnClickListener clickListener = new OnClickListener() { public void onClick(View v) { // 发起搜索 SearchButtonProcess(v); } }; OnClickListener nextLineClickListener = new OnClickListener() { public void onClick(View v) { // 搜索下一条公交线 SearchNextBusline(); } }; OnClickListener nodeClickListener = new OnClickListener() { public void onClick(View v) { // 浏览路线节点 nodeClick(v); } }; mBtnSearch.setOnClickListener(clickListener); mBtnNextLine.setOnClickListener(nextLineClickListener); mBtnPre.setOnClickListener(nodeClickListener); mBtnNext.setOnClickListener(nodeClickListener); } /** * 发起检索 * * @param v */ void SearchButtonProcess(View v) { busLineIDList.clear(); busLineIndex = 0; mBtnPre.setVisibility(View.INVISIBLE); mBtnNext.setVisibility(View.INVISIBLE); if (mBtnSearch.equals(v)) { EditText editCity = (EditText) findViewById(R.id.city); EditText editSearchKey = (EditText) findViewById(R.id.searchkey); // 发起poi检索,从得到所有poi中找到公交线路类型的poi,再使用该poi的id进行公交详情搜索 mSearch.poiSearchInCity(editCity.getText().toString(), editSearchKey.getText().toString()); } } void SearchNextBusline() { if (busLineIndex >= busLineIDList.size()) { busLineIndex = 0; } if (busLineIndex >= 0 && busLineIndex < busLineIDList.size() && busLineIDList.size() > 0) { mSearch.busLineSearch(((EditText) findViewById(R.id.city)) .getText().toString(), busLineIDList.get(busLineIndex)); busLineIndex++; } } /** * 创建弹出泡泡图层 */ public void createPaopao() { viewCache = getLayoutInflater() .inflate(R.layout.custom_text_view, null); popupText = (TextView) viewCache.findViewById(R.id.textcache); // 泡泡点击响应回调 PopupClickListener popListener = new PopupClickListener() { @Override public void onClickedPopup(int index) { Log.v("click", "clickapoapo"); } }; pop = new PopupOverlay(mMapView, popListener); } /** * 节点浏览示例 * * @param v */ public void nodeClick(View v) { if (nodeIndex < -1 || route == null || nodeIndex >= route.getNumSteps()) return; viewCache = getLayoutInflater() .inflate(R.layout.custom_text_view, null); popupText = (TextView) viewCache.findViewById(R.id.textcache); // 上一个节点 if (mBtnPre.equals(v) && nodeIndex > 0) { // 索引减 nodeIndex--; // 移动到指定索引的坐标 mMapView.getController().animateTo( route.getStep(nodeIndex).getPoint()); // 弹出泡泡 popupText.setText(route.getStep(nodeIndex).getContent()); popupText.setBackgroundResource(R.drawable.popup); pop.showPopup(BMapUtil.getBitmapFromView(popupText), route.getStep(nodeIndex).getPoint(), 5); } // 下一个节点 if (mBtnNext.equals(v) && nodeIndex < (route.getNumSteps() - 1)) { // 索引加 nodeIndex++; // 移动到指定索引的坐标 mMapView.getController().animateTo( route.getStep(nodeIndex).getPoint()); // 弹出泡泡 popupText.setText(route.getStep(nodeIndex).getContent()); popupText.setBackgroundDrawable(getResources().getDrawable( R.drawable.popup)); pop.showPopup(BMapUtil.getBitmapFromView(popupText), route.getStep(nodeIndex).getPoint(), 5); } } @Override protected void onPause() { mMapView.onPause(); super.onPause(); } @Override protected void onResume() { mMapView.onResume(); super.onResume(); } @Override protected void onDestroy() { mMapView.destroy(); super.onDestroy(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mMapView.onSaveInstanceState(outState); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); mMapView.onRestoreInstanceState(savedInstanceState); } }
布局XML:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="在" /> <EditText android:id="@+id/city" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="北京" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="市内找" /> <EditText android:id="@+id/searchkey" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="717" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="公交车" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:id="@+id/search" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="2dip" android:layout_marginRight="2dip" android:layout_weight="1" android:background="@drawable/button_style" android:text="开始" /> <Button android:id="@+id/nextline" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="2dip" android:layout_marginRight="2dip" android:layout_weight="1" android:background="@drawable/button_style" android:text="下一条" /> </LinearLayout> </LinearLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" > <com.baidu.mapapi.map.MapView android:id="@+id/bmapView" android:layout_width="match_parent" android:layout_height="match_parent" android:clickable="true" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignWithParentIfMissing="false" android:layout_centerHorizontal="true" android:layout_centerVertical="false" android:layout_marginBottom="10dip" > <Button android:id="@+id/pre" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="2dip" android:layout_marginRight="2dip" android:layout_weight="1.0" android:background="@drawable/pre_" /> <Button android:id="@+id/next" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="2dip" android:layout_marginRight="2dip" android:layout_weight="1.0" android:background="@drawable/next_" /> </LinearLayout> </RelativeLayout> </LinearLayout>
配置文件和Application类同上文
附上图片效果:
一.交叉编译
1.官网下载http://www.ntp.org/点击download选项页
我的版本是ntp-4.2.6p5.tar.gz
2.解压
tar -zxvf ntp-4.2.6p5.tar.gz
3.进入解压目录配置
./configure --host=arm-linux CC=arm-none-linux-gnueabi-gcc
或者指定安装路径
./configure --host=arm-linux CC=arm-none-linux-gnueabi-gcc --prefix=/home/m/3rd/tmp
4.make和[make install]
5.生成
/bin(ntpd,ntpdate,ntpdc,ntp-keygen,ntpd,ntptime,sntp,tickadj...)
/lib
/sbin
/share (man)
目录拷贝到目标文件系统
二.配置测试ntp服务器
拷贝host系统/etc目录下的ntp.conf文件到目标系统/etc下,没有的话就先安装ntp服务就会有了(ubuntu 下sudo apt-get install ntp)
或者拷贝我的文件内容
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help driftfile /var/lib/ntp/ntp.drift # Enable this if you want statistics to be logged. #statsdir /var/log/ntpstats/ statistics loopstats peerstats clockstats filegen loopstats file loopstats type day enable filegen peerstats file peerstats type day enable filegen clockstats file clockstats type day enable # You do need to talk to an NTP server or two (or three). server ntp.ubuntu.com # Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for # details. The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions> # might also be helpful. # # Note that "restrict" applies to both servers and clients, so a configuration # that might be intended to block requests from certain clients could also end # up blocking replies from your own upstream servers. # By default, exchange time with everybody, but don't allow configuration. restrict -4 default kod notrap nomodify nopeer noquery restrict -6 default kod notrap nomodify nopeer noquery # Local users may interrogate the ntp server more closely. restrict 127.0.0.1 restrict ::1 # Clients from this (example!) subnet have unlimited access, but only if # cryptographically authenticated. #restrict 192.168.123.0 mask 255.255.255.0 notrust # If you want to provide time to your local subnet, change the next line. # (Again, the address is an example only.) #broadcast 192.168.123.255 # If you want to listen to time broadcasts on your local subnet, de-comment the # next lines. Please do this only if you trust everybody on the network! #disable auth #broadcastclient
测试
date 命令查看时间日期,
date 11111111修改时间
Mon Nov 11 11:11:00 UTC 2013
运行ntpdate 64.4.10.33更新时间 ip是ntp服务器的地址
11 Sep 05:13:21 ntpdate[1851]: adjust time server 64.4.10.33 offset -0.037363 sec
再次运行date
Wed Sep 11 04:49:01 UTC 2013
ntp时间服务器可以查看windows的时间设置
ping 一下ping time.windows.com
正在 Ping time.microsoft.akadns.net [64.4.10.33] 具有 32 字节的数据:
试了一下 直接ntpdate time.windows.com也行的
(外网要能连通 设置DNS
vi /etc/resolv.conf添加
nameserver 【dns地址】
)
本文中将介绍在百度地图上添加覆盖物的功能、响应点击功能和弹出pop功能,代码来自百度Demo:
Activity:
package com.home; import java.util.ArrayList; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import com.baidu.mapapi.BMapManager; import com.baidu.mapapi.map.ItemizedOverlay; import com.baidu.mapapi.map.MapController; import com.baidu.mapapi.map.MapView; import com.baidu.mapapi.map.OverlayItem; import com.baidu.mapapi.map.PopupClickListener; import com.baidu.mapapi.map.PopupOverlay; import com.baidu.platform.comapi.basestruct.GeoPoint; /** * 演示覆盖物的用法 */ public class OverlayActivity extends Activity { /** * MapView 是地图主控件 */ private MapView mMapView = null; /** * 用MapController完成地图控制 */ private MapController mMapController = null; private MyOverlay mOverlay = null; private PopupOverlay pop = null; private ArrayList<OverlayItem> mItems = null; private TextView popupText = null; private View viewCache = null; private View popupInfo = null; private View popupLeft = null; private View popupRight = null; private Button button = null; private MapView.LayoutParams layoutParam = null; private OverlayItem mCurItem = null; /** * overlay 位置坐标 */ double mLon1 = 116.400244; double mLat1 = 39.963175; double mLon2 = 116.369199; double mLat2 = 39.942821; double mLon3 = 116.425541; double mLat3 = 39.939723; double mLon4 = 116.401394; double mLat4 = 39.906965; double mLon5 = 116.402096; double mLat5 = 39.942057; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /** * 使用地图sdk前需先初始化BMapManager. BMapManager是全局的,可为多个MapView共用,它需要地图模块创建前创建, * 并在地图地图模块销毁后销毁,只要还有地图模块在使用,BMapManager就不应该销毁 */ DemoApplication app = (DemoApplication) this.getApplication(); if (app.mBMapManager == null) { app.mBMapManager = new BMapManager(this); /** * 如果BMapManager没有初始化则初始化BMapManager */ app.mBMapManager.init(DemoApplication.strKey, new DemoApplication.MyGeneralListener()); } /** * 由于MapView在setContentView()中初始化,所以它需要在BMapManager初始化之后 */ setContentView(R.layout.activity_overlay); mMapView = (MapView) findViewById(R.id.bmapView); /** * 获取地图控制器 */ mMapController = mMapView.getController(); /** * 设置地图是否响应点击事件 . */ mMapController.enableClick(true); /** * 设置地图缩放级别 */ mMapController.setZoom(14); /** * 显示内置缩放控件 */ mMapView.setBuiltInZoomControls(true); initOverlay(); /** * 设定地图中心点 */ GeoPoint p = new GeoPoint((int) (mLat5 * 1E6), (int) (mLon5 * 1E6)); mMapController.setCenter(p); } public void initOverlay() { /** * 创建自定义overlay */ mOverlay = new MyOverlay(getResources().getDrawable( R.drawable.icon_marka), mMapView); /** * 准备overlay 数据 */ GeoPoint p1 = new GeoPoint((int) (mLat1 * 1E6), (int) (mLon1 * 1E6)); OverlayItem item1 = new OverlayItem(p1, "覆盖物1", ""); /** * 设置overlay图标,如不设置,则使用创建ItemizedOverlay时的默认图标. */ item1.setMarker(getResources().getDrawable(R.drawable.icon_marka)); GeoPoint p2 = new GeoPoint((int) (mLat2 * 1E6), (int) (mLon2 * 1E6)); OverlayItem item2 = new OverlayItem(p2, "覆盖物2", ""); item2.setMarker(getResources().getDrawable(R.drawable.icon_markb)); GeoPoint p3 = new GeoPoint((int) (mLat3 * 1E6), (int) (mLon3 * 1E6)); OverlayItem item3 = new OverlayItem(p3, "覆盖物3", ""); item3.setMarker(getResources().getDrawable(R.drawable.icon_markc)); GeoPoint p4 = new GeoPoint((int) (mLat4 * 1E6), (int) (mLon4 * 1E6)); OverlayItem item4 = new OverlayItem(p4, "覆盖物4", ""); item4.setMarker(getResources().getDrawable(R.drawable.icon_markd)); GeoPoint p5 = new GeoPoint((int) (mLat5 * 1E6), (int) (mLon5 * 1E6)); OverlayItem item5 = new OverlayItem(p5, "覆盖物5", ""); item5.setMarker(getResources().getDrawable(R.drawable.icon_gcoding)); /** * 将item 添加到overlay中 注意: 同一个item只能add一次 */ mOverlay.addItem(item1); mOverlay.addItem(item2); mOverlay.addItem(item3); mOverlay.addItem(item4); mOverlay.addItem(item5); /** * 保存所有item,以便overlay在reset后重新添加 */ mItems = new ArrayList<OverlayItem>(); mItems.addAll(mOverlay.getAllItem()); /** * 将overlay 添加至MapView中 */ mMapView.getOverlays().add(mOverlay); /** * 刷新地图 */ mMapView.refresh(); /** * 向地图添加自定义View. */ viewCache = getLayoutInflater() .inflate(R.layout.custom_text_view, null); popupInfo = (View) viewCache.findViewById(R.id.popinfo); popupLeft = (View) viewCache.findViewById(R.id.popleft); popupRight = (View) viewCache.findViewById(R.id.popright); popupText = (TextView) viewCache.findViewById(R.id.textcache); button = new Button(this); button.setBackgroundResource(R.drawable.popup); /** * 创建一个popupoverlay */ PopupClickListener popListener = new PopupClickListener() { @Override public void onClickedPopup(int index) { if (index == 0) { // 更新item位置 pop.hidePop(); GeoPoint p = new GeoPoint(mCurItem.getPoint() .getLatitudeE6() + 5000, mCurItem.getPoint() .getLongitudeE6() + 5000); mCurItem.setGeoPoint(p); mOverlay.updateItem(mCurItem); mMapView.refresh(); } else if (index == 2) { // 更新图标 mCurItem.setMarker(getResources().getDrawable( R.drawable.nav_turn_via_1)); mOverlay.updateItem(mCurItem); mMapView.refresh(); } } }; pop = new PopupOverlay(mMapView, popListener); } /** * 清除所有Overlay * * @param view */ public void clearOverlay(View view) { mOverlay.removeAll(); if (pop != null) { pop.hidePop(); } mMapView.removeView(button); mMapView.refresh(); } /** * 重新添加Overlay * * @param view */ public void resetOverlay(View view) { clearOverlay(null); // 重新add overlay mOverlay.addItem(mItems); mMapView.refresh(); } @Override protected void onPause() { /** * MapView的生命周期与Activity同步,当activity挂起时需调用MapView.onPause() */ mMapView.onPause(); super.onPause(); } @Override protected void onResume() { /** * MapView的生命周期与Activity同步,当activity恢复时需调用MapView.onResume() */ mMapView.onResume(); super.onResume(); } @Override protected void onDestroy() { /** * MapView的生命周期与Activity同步,当activity销毁时需调用MapView.destroy() */ mMapView.destroy(); super.onDestroy(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mMapView.onSaveInstanceState(outState); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); mMapView.onRestoreInstanceState(savedInstanceState); } public class MyOverlay extends ItemizedOverlay { public MyOverlay(Drawable defaultMarker, MapView mapView) { super(defaultMarker, mapView); } @Override public boolean onTap(int index) { OverlayItem item = getItem(index); mCurItem = item; if (index == 4) { button.setText("这是一个系统控件"); GeoPoint pt = new GeoPoint((int) (mLat5 * 1E6), (int) (mLon5 * 1E6)); // 创建布局参数 layoutParam = new MapView.LayoutParams( // 控件宽,继承自ViewGroup.LayoutParams MapView.LayoutParams.WRAP_CONTENT, // 控件高,继承自ViewGroup.LayoutParams MapView.LayoutParams.WRAP_CONTENT, // 使控件固定在某个地理位置 pt, 0, -32, // 控件对齐方式 MapView.LayoutParams.BOTTOM_CENTER); // 添加View到MapView中 mMapView.addView(button, layoutParam); } else { popupText.setText(getItem(index).getTitle()); Bitmap[] bitMaps = { BMapUtil.getBitmapFromView(popupLeft), BMapUtil.getBitmapFromView(popupInfo), BMapUtil.getBitmapFromView(popupRight) }; pop.showPopup(bitMaps, item.getPoint(), 32); } return true; } @Override public boolean onTap(GeoPoint pt, MapView mMapView) { if (pop != null) { pop.hidePop(); mMapView.removeView(button); } return false; } } }
地图工具类(BMapUtil)同上文。
custom_text_view.xml同上文。
配置文件及Application类均与之前的一样。
布局文件:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:id="@+id/clear" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginBottom="2dip" android:layout_marginLeft="2dip" android:layout_marginRight="2dip" android:layout_marginTop="2dip" android:layout_weight="1" android:background="@drawable/button_style" android:onClick="clearOverlay" android:padding="10dip" android:text="清除(clear)" /> <Button android:id="@+id/resert" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginBottom="2dip" android:layout_marginLeft="2dip" android:layout_marginRight="2dip" android:layout_marginTop="2dip" android:layout_weight="1" android:background="@drawable/button_style" android:onClick="resetOverlay" android:text="重置(reset)" /> </LinearLayout> <com.baidu.mapapi.map.MapView android:id="@+id/bmapView" android:layout_width="match_parent" android:layout_height="match_parent" android:clickable="true" /> </LinearLayout>
附上图片效果: