Android 获取地理位置获取经纬度

下载jar https://pan.baidu.com/s/1ioZ5_24WvsmMYxIcgoLyvA

复制到libs下

附代码

static BDLocation lastLocation = null;
private LocationClient mLocClient;
public MyLocationListenner myListener = new MyLocationListenner();
    public class MyLocationListenner implements BDLocationListener {
        @Override
        public void onReceiveLocation(BDLocation location) {
            if (location == null) {
                return;
            }
            Log.d("map", "On location change received:" + location);
            Log.d("map", "addr:" + location.getAddrStr());

            if (lastLocation != null) {
                if (lastLocation.getLatitude() == location.getLatitude() && lastLocation.getLongitude() == location.getLongitude()) {
                    Log.d("map", "same location, skip refresh");
                    // mMapView.refresh(); //need this refresh?
                    return;
                }
            }
            String addrlg; //定位结果
            lastLocation = location;
            if (!TextUtils.isEmpty(lastLocation.getLocationDescribe())){
                addrlg = lastLocation.getLocationDescribe();
            }else if (lastLocation.hasAddr()) {
                addrlg = lastLocation.getAddrStr();
            }else {
                addrlg = "定位失败...";
                return;
            }
            String city = lastLocation.getCity();
            double lat = lastLocation.getLatitude();
            double lot = lastLocation.getLongitude();
            ShareUtil.sharedPstring("nowla",String.valueOf(lat));
            ShareUtil.sharedPstring("nowlo",String.valueOf(lot));
            Log.i("lgq","............"+addrlg+"........"+lat+"......."+lot);
//            tv_bottom_bar_me.setText(addrlg);
//            mBaiduMap.animateMapStatus(u);
        }
    }
private void showMapWithLocationClient() {

    mLocClient = new LocationClient(this);
    mLocClient.registerLocationListener(myListener);

    LocationClientOption option = new LocationClientOption();
    option.setOpenGps(true);// open gps
    // option.setCoorType("bd09ll");
    // Johnson change to use gcj02 coordination. chinese national standard
    // so need to conver to bd09 everytime when draw on baidu map
    option.setCoorType("gcj02");
    option.setScanSpan(30000);
    option.setAddrType("all");
    mLocClient.setLocOption(option);

    mLocClient.start();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    showMapWithLocationClient();

}



谷歌API也可以实现啦:https://blog.csdn.net/meixi_android/article/details/84955589

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值