百度地图点mapView获取经纬度

 

在onCreate()里调mMapView.getOverlays().add(new GetOverlay());

 

class GetOverlay extends Overlay{
                GeoPoint geo;
                @Override
                public void draw(Canvas canvas, MapView mapView, boolean arg2) {
                        super.draw(canvas, mapView, arg2);
                        if(geo==null){
                                return;
                        }
                        Log.d(toString(), arg2+"-------draw--");
                        Projection projection = mapView.getProjection(); 
                        // 把经纬度变换到相对于MapView左上角的屏幕像素坐标
                        Point point = projection.toPixels(geo, null); 
                        // 可在此处添加您的绘制代码
                        Paint paintText = new Paint();
                        paintText.setColor(Color.RED);
                        paintText.setTextSize(35);
                        canvas.drawText("●", point.x-9, point.y+13, paintText); // 绘制文本
                }

                @Override
                public boolean onTap(GeoPoint geo, MapView arg1) {
                        Log.d(this.toString(), geo.getLongitudeE6()/1E6+"----------"+geo.getLatitudeE6()/1E6);
                        return super.onTap(geo, arg1);
                }
                
        }


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好,关于使用百度地图获取经纬度的问题,您可以按照以下步骤进行操作: 1. 在 AndroidManifest.xml 文件中添加以下权限: <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 2. 在布局文件中添加 MapView 控件: <com.baidu.mapapi.map.MapView android:id="@+id/bmapView" android:layout_width="match_parent" android:layout_height="match_parent" app:mapType="normal"/> 3. 在 Activity 中初始化百度地图 SDK: // 获取地图控件引用 MapView mMapView = (MapView) findViewById(R.id.bmapView); // 获取 BaiduMap 对象 BaiduMap mBaiduMap = mMapView.getMap(); // 开启定位图层 mBaiduMap.setMyLocationEnabled(true); 4. 在 Activity 中实现 LocationListener 接口,获取当前位置的经纬度: public class MyLocationListener implements BDLocationListener { @Override public void onReceiveLocation(BDLocation location) { if (location == null || mMapView == null) { return; } // 获取经纬度 double latitude = location.getLatitude(); double longitude = location.getLongitude(); } } 5. 在 Activity 中启动定位服务,获取当前位置的经纬度: // 初始化定位 LocationClient mLocationClient = new LocationClient(getApplicationContext()); // 注册监听函数 mLocationClient.registerLocationListener(new MyLocationListener()); // 配置定位参数 LocationClientOption option = new LocationClientOption(); option.setOpenGps(true); // 打开 GPS option.setCoorType("bd09ll"); // 设置坐标类型 option.setScanSpan(100); // 设置定位间隔时间 mLocationClient.setLocOption(option); // 启动定位服务 mLocationClient.start(); 以上就是使用百度地图获取经纬度的具体示例,希望能对您有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值