Пример #1
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());
   }
 }
Пример #2
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());
   }
 }
Пример #3
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();
  }