石家庄停车位在线预约平台05

安卓定位:具体位置显示

由于只看经纬度我们无法一下子知道自己的具体位置,所以引入具体位置显示。只需要修改MainActivity.java即可。
修改部分:
(1)、先是调用了setIsNeedAddress传入true,表示我们需要获取当前具体的位置

private void initLocation() {
        LocationClientOption option = new LocationClientOption();
        option.setScanSpan(5000);
       // option.setLocationMode(LocationClientOption.LocationMode.Device_Sensors);
        option.setIsNeedAddress(true);
        mLocationClient.setLocOption(option);
    }

(2)、调用getProvince、getCity等函数获得具体的位置信息。

public class MyLocationListener implements BDLocationListener {
     @Override
     public void onReceiveLocation(final BDLocation location) {
        runOnUiThread(new Runnable() {
         @Override
         public void run() {
            currentPosition = new StringBuilder();
            currentPosition.append("纬度:").append(location.getLatitude()).append("\n");
            currentPosition.append("经度:").append(location.getLongitude()).append("\n");
            currentPosition.append("国家:").append(location.getCountry()).append("\n");
            currentPosition.append("省:").append(location.getProvince()).append("\n");
            currentPosition.append("市:").append(location.getCity()).append("\n");
            currentPosition.append("区:").append(location.getDistrict()).append("\n");
            currentPosition.append("街道:").append(location.getStreet()).append("\n");
            currentPosition.append("定位方式:");
            if (location.getLocType() == BDLocation.TypeGpsLocation) {
                currentPosition.append("GPS");
            } else if (location.getLocType() == BDLocation.TypeNetWorkLocation) {
                currentPosition.append("网络");
            }
            positionText.setText(currentPosition);
         }
     });
    }
  }

 

posted on 2020-02-05 21:01  xiaohaigege666  阅读(144)  评论(0编辑  收藏  举报

导航