android百度地图开发V4.5最新版(2)---地理位置的获取

接着上篇博客,如果没有看,点击http://blog.csdn.net/u012115730/article/details/78738159进行查看。这篇博客我们介绍下定位功能即地理位置的获取。废话不多说,直接撸起。

第一步:新建xml文件。这个xml只有一个按钮和一个listView。我这里不要加载百度地图,只获取地理位置。

<Button
    android:id="@+id/bt_dignshi"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="定时获得经纬度"
    android:layout_gravity="center"
    />
 <ListView
     android:id="@+id/android:list"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     >
 </ListView>
第二步:建立位置监听

 // 注册位置监听器
        locationClient.registerLocationListener(new BDLocationListener() {
            @Override
            public void onReceiveLocation(BDLocation location) {
                // TODO Auto-generated method stub
                if (location == null) {
                    return;
                }
                StringBuffer sb = new StringBuffer(256);
                sb.append("时间:");
                sb.append(location.getTime());
                sb.append("纬度 : ");
                sb.append(location.getLatitude());
                sb.append("经度 : ");
                sb.append(location.getLongitude());
                sb.append("地址:");
                sb.append(location.getAddrStr());
                Log.e("经纬度",sb.toString());
                Map<String, String> map1 = new HashMap<String, String>();
                map1.put("经纬度",sb.toString());
                data.add(map1);
                setListAdapter(new SimpleAdapter(DSJWDActivity.this,data,android.R.layout.simple_list_item_1,
                        new String[]{"经纬度"},            //每行显示一个姓名
                        new int[]{android.R.id.text1}));   //名字在text1上显示));
            }
        });
        locationClient.start();
    }
});
第三步:建立定位条件:

// 设置定位条件
LocationClientOption option = new LocationClientOption();
option.setIsNeedAddress(true);// 中文地址
option.setOpenGps(true); // 是否打开GPS
option.setCoorType("bd09ll"); // 设置返回值的坐标类型。
option.setPriority(LocationClientOption.NetWorkFirst); // 设置定位优先级
// option.setProdName("LocationDemo"); //
option.setLocationMode(LocationClientOption.LocationMode.Battery_Saving);// 设置定位模式
option.setScanSpan(10000*5);//检查周期 小于1秒的按1// 设置产品线名称。强烈建议您使用自定义的产品线名称,方便我们以后为您提供更高效准确的定位服务。
// option.setScanSpan(UPDATE_TIME);// 设置定时定位的时间间隔。单位毫秒
locationClient.setLocOption(option);
 三步走完我们就可以出现我们想要的效果: 
 
 

 
 
 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值