@Override
  public void onLocationChanged(AMapLocation aMapLocation) {

    if (aMapLocation != null) {
      //                this.aMapLocation = ;location// 判断超时机制
      Log.d(TAG, "err: " + aMapLocation.getAMapException().getErrorMessage());
      Double geoLat = aMapLocation.getLatitude();
      Double geoLng = aMapLocation.getLongitude();
      String cityCode = "";
      String desc = "";
      Bundle locBundle = aMapLocation.getExtras();
      if (locBundle != null) {
        cityCode = locBundle.getString("citycode");
        desc = locBundle.getString("desc");
      }
      String str =
          ("定位成功:("
              + geoLng
              + ","
              + geoLat
              + ")"
              + "\n精    度    :"
              + aMapLocation.getAccuracy()
              + "米"
              + "\n定位方式:"
              + aMapLocation.getProvider()
              + "\n定位时间:"
              + "  "
              + "\n城市编码:"
              + cityCode
              + "\n位置描述:"
              + desc
              + "\n省:"
              + aMapLocation.getProvince()
              + "\n市:"
              + aMapLocation.getCity()
              + "\n区(县):"
              + aMapLocation.getDistrict()
              + "\n区域编码:"
              + aMapLocation.getAdCode());
      searchText.setText(aMapLocation.getAddress());
    }
  }
示例#2
0
 @Override
 public void onLocationChanged(AMapLocation amapLocation) {
   if (amapLocation != null && amapLocation.getAMapException().getErrorCode() == 0) {
     // get geoinfo
     Double lati = amapLocation.getLatitude();
     Double logti = amapLocation.getLongitude();
     String address = amapLocation.getAddress();
     String province = amapLocation.getProvince();
     String country = amapLocation.getCountry();
     String city = amapLocation.getCity();
     String citycode = amapLocation.getCityCode();
     String district = amapLocation.getDistrict();
     String street = amapLocation.getStreet();
     float Accuracy = amapLocation.getAccuracy();
     String road = amapLocation.getRoad();
     geo.setLatitude(lati);
     geo.setLongitude(logti);
     geo.setAddress(address);
     geo.setProvince(province);
     geo.setCountry(country);
     geo.setCity(city);
     geo.setCitycode(citycode);
     geo.setDistrict(district);
     geo.setStreet(street);
     geo.setAccuracy(Accuracy);
     geo.setRoad(road);
     LogUtil.v(
         "Location info: ",
         lati + " " + logti + " " + address + " " + province + " " + country + " " + city + " "
             + citycode + " " + district + " " + street + " " + Accuracy + " " + road);
     loadNear();
   } else {
     this.stopLocation();
     onLoad();
     this.mTexthint.setClickable(true);
     this.mTexthint.setText(getString(R.string.get_no_position));
     LogUtil.v("NearFragment info: ", "enter onLocationChanged() + ERROR!");
     LogUtil.v(
         "NearFragment info : AmapErr",
         "Location ERR:" + amapLocation.getAMapException().getErrorCode());
   }
 }
示例#3
0
 @Override
 public void onLocationChanged(AMapLocation amapLocation) {
   LogUtil.v(
       "MessboardActivity info: ", "enter onLocationChanged()!" + amapLocation.getLatitude());
   if (amapLocation != null && amapLocation.getAMapException().getErrorCode() == 0) {
     LogUtil.v("MessboardActivity info: ", "enter onLocationChanged()!" + " enter IF!");
     // get geoinfo
     Double lati = amapLocation.getLatitude();
     Double logti = amapLocation.getLongitude();
     String address = amapLocation.getAddress();
     String province = amapLocation.getProvince();
     String country = amapLocation.getCountry();
     String city = amapLocation.getCity();
     String citycode = amapLocation.getCityCode();
     String district = amapLocation.getDistrict();
     String street = amapLocation.getStreet();
     float Accuracy = amapLocation.getAccuracy();
     String road = amapLocation.getRoad();
     geo.setLatitude(lati);
     geo.setLongitude(logti);
     geo.setAddress(address);
     geo.setProvince(province);
     geo.setCountry(country);
     geo.setCity(city);
     geo.setCitycode(citycode);
     geo.setDistrict(district);
     geo.setStreet(street);
     geo.setAccuracy(Accuracy);
     geo.setRoad(road);
     LogUtil.v(
         "Location info: ",
         lati + " " + logti + " " + address + " " + province + " " + country + " " + city + " "
             + citycode + " " + district + " " + street + " " + Accuracy + " " + road);
     this.calculateDistance(lati, logti);
   } else {
     LogUtil.v("MessboardActivity info: ", "enter onLocationChanged() + ERROR!");
     Log.e("AmapErr", "Location ERR:" + amapLocation.getAMapException().getErrorCode());
   }
 }
示例#4
0
  /**
   * 根据定位结果返回定位信息的字符串
   *
   * @param loc
   * @return
   */
  public static synchronized String getLocationStr(AMapLocation location) {
    if (null == location) {
      return null;
    }
    StringBuffer sb = new StringBuffer();
    // errCode等于0代表定位成功,其他的为定位失败,具体的可以参照官网定位错误码说明
    if (location.getErrorCode() == 0) {
      sb.append("定位成功" + "\n");
      sb.append("定位类型: " + location.getLocationType() + "\n");
      sb.append("经    度    : " + location.getLongitude() + "\n");
      sb.append("纬    度    : " + location.getLatitude() + "\n");
      sb.append("精    度    : " + location.getAccuracy() + "米" + "\n");
      sb.append("提供者    : " + location.getProvider() + "\n");

      if (location.getProvider().equalsIgnoreCase(android.location.LocationManager.GPS_PROVIDER)) {
        // 以下信息只有提供者是GPS时才会有
        sb.append("速    度    : " + location.getSpeed() + "米/秒" + "\n");
        sb.append("角    度    : " + location.getBearing() + "\n");
        // 获取当前提供定位服务的卫星个数
        sb.append("星    数    : " + location.getExtras().getInt("satellites", 0) + "\n");
      } else {
        // 供者是GPS时是没有以下信息的
        sb.append("国    家    : " + location.getCountry() + "\n");
        sb.append("省            : " + location.getProvince() + "\n");
        sb.append("市            : " + location.getCity() + "\n");
        sb.append("区            : " + location.getDistrict() + "\n");
        sb.append("地    址    : " + location.getAddress() + "\n");
      }
    } else {
      // 定位失败
      sb.append("定位为失败" + "\n");
      sb.append("错误码:" + location.getErrorCode() + "\n");
      sb.append("错误信息:" + location.getErrorInfo() + "\n");
      sb.append("错误描述:" + location.getLocationDetail() + "\n");
    }
    return sb.toString();
  }