设为首页 加入收藏

TOP

Android定位&地图&导航——基于百度地图移动获取位置和自动定位(三)
2017-10-12 11:29:24 】 浏览:4633
Tags:Android定位 地图 导航 基于 百度 移动 获取 位置 自动 定位
eTo(
new GeoPoint((int) (locData.latitude * 1e6), (int) (locData.longitude * 1e6)), mHandler .obtainMessage(1)); } public void onReceivePoi(BDLocation poiLocation) { if (poiLocation == null) { return; } } } public class NotifyLister extends BDNotifyListener { public void onNotify(BDLocation mlocation, float distance) { } } @Override protected void onPause() { mMapView.onPause(); super.onPause(); } @Override protected void onResume() { mMapView.onResume(); super.onResume(); } @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 static void getPosition(GeoPoint g) { mkSerach.reverseGeocode(g); showAddr.setText("获取位置中..."); } }

Xml布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
  
     >
    <TextView 
        android:id="@+id/showAddr"
          android:gravity="center"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="选择地点"
        android:textSize="20dp"
        /> 
 <com.baidu.mapapi.map.MapView
        android:id="@+id/bmapsView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true" />     
</LinearLayout>
三、绘制图形

 MyIcon 的onDraw实现绘制中心点的图标,MyIcon2绘制指示器图标,如图所示

 

public class MyIcon extends View {
    public static int w;
    public static int h;
    public static  Bitmap mBitmap;

    public MyIcon(Context context) {
        super(context);
        mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.me);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        w = this.getWidth() / 2 - mBitmap.getWidth() / 2;
        h = this.getHeight() / 2 - mBitmap.getHeight() / 2;
        canvas.drawBitmap(mBitmap, w, h, null);
    }

}
public class MyIcon2 extends View{
    public static int w;
    public static int h;
    private Bitmap mBitmap;

    public MyIcon2(Context context) {
        super(context);
        mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.jiewo);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        w = this.getWidth() / 2 - mBitmap.getWidth() / 2;
        h = (this.getHeight() / 2 - mBitmap.getHeight() / 2) - (    MyIcon.mBitmap.getHeight()/2);
        canvas.drawBitmap(mBitmap, w, h, null);
    }
}

 

作者:杰瑞教育
出处: http://www.cnblogs.com/jerehedu/ 
版权声明:本文版权归 杰瑞教育 技有限公司和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
技术咨询:JRedu技术交流
 
首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇【同行说技术】Android程序员从小.. 下一篇Android定位&地图&导航——基于百..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目