android.location.Address.getAddressLine()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(146)

本文整理了Java中android.location.Address.getAddressLine()方法的一些代码示例,展示了Address.getAddressLine()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Address.getAddressLine()方法的具体详情如下:
包路径:android.location.Address
类名称:Address
方法名:getAddressLine

Address.getAddressLine介绍

暂无

代码示例

代码示例来源:origin: square/assertj-android

public AddressAssert hasAddressLine(int index, String line) {
 isNotNull();
 String actualLine = actual.getAddressLine(index);
 assertThat(actualLine) //
   .overridingErrorMessage("Expected address line %s <%s> but was <%s>.", index, line,
     actualLine) //
   .isEqualTo(line);
 return this;
}

代码示例来源:origin: yaozs/YzsLib

/**
 * 根据经纬度获取所在街道
 *
 * @param latitude  纬度
 * @param longitude 经度
 * @return {@link Address}
 */
public String getStreet(double latitude, double longitude) {
  Address address = getAddress(latitude, longitude);
  return address == null ? "unknown" : address.getAddressLine(0);
}

代码示例来源:origin: florent37/RxGps

private String getAddressText(Address address) {
  String addressText = "";
  final int maxAddressLineIndex = address.getMaxAddressLineIndex();
  for (int i = 0; i <= maxAddressLineIndex; i++) {
    addressText += address.getAddressLine(i);
    if (i != maxAddressLineIndex) {
      addressText += "\n";
    }
  }
  return addressText;
}

代码示例来源:origin: lianghuiyong/AndroidBase

/**
 * 根据经纬度获取所在街道
 *
 * @param latitude  纬度
 * @param longitude 经度
 * @return 所在街道
 */
public static String getStreet(double latitude, double longitude) {
  Address address = getAddress(latitude, longitude);
  return address == null ? "unknown" : address.getAddressLine(0);
}

代码示例来源:origin: StannyBing/ZXUtils

/**
 * 根据经纬度获取所在街道
 *
 * @param latitude  纬度
 * @param longitude 经度
 * @return 所在街道
 */
public static String getStreet(double latitude, double longitude) {
  Address address = getAddress(latitude, longitude);
  return address == null ? "unknown" : address.getAddressLine(0);
}

代码示例来源:origin: 0xm1nam0/RxCore

/**
 * 根据经纬度获取所在街道
 *
 * @param latitude  纬度
 * @param longitude 经度
 * @return 所在街道
 */
public static String getStreet(double latitude, double longitude) {
  Address address = getAddress(latitude, longitude);
  return address == null ? "unknown" : address.getAddressLine(0);
}

代码示例来源:origin: dsolonenko/financisto

public static String addressToString(Address address) {
  StringBuilder sb = new StringBuilder();
  int max = address.getMaxAddressLineIndex();
  for (int i = max; i >= 0; i--) {
    String line = address.getAddressLine(i);
    if (i < max) {
      sb.append(", ");        			
    }
    sb.append(line);
  }
  return sb.toString();
}

代码示例来源:origin: hoangkien0705/Android-UtilCode

/**
 * 根据经纬度获取所在街道
 *
 * @param latitude  纬度
 * @param longitude 经度
 * @return 所在街道
 */
public static String getStreet(double latitude, double longitude) {
  Address address = getAddress(latitude, longitude);
  return address == null ? "unknown" : address.getAddressLine(0);
}

代码示例来源:origin: rohitsthaa/retrofit-openweather

/**
 * Try to get AddressLine
 * @return null or addressLine
 */
public String getAddressLine(Context context) {
  List<Address> addresses = getGeocoderAddress(context);
  if (addresses != null && addresses.size() > 0) {
    Address address = addresses.get(0);
    String addressLine = address.getAddressLine(0);
    return addressLine;
  } else {
    return null;
  }
}

代码示例来源:origin: com.squareup.assertj/assertj-android

public AddressAssert hasAddressLine(int index, String line) {
 isNotNull();
 String actualLine = actual.getAddressLine(index);
 assertThat(actualLine) //
   .overridingErrorMessage("Expected address line %s <%s> but was <%s>.", index, line,
     actualLine) //
   .isEqualTo(line);
 return this;
}

代码示例来源:origin: Sishin/MapLocation

/**
 * Sends a resultCode and message to the receiver.
 */
private void deliverResultToReceiver(int resultCode, String message, Address address) {
  try {
    Bundle bundle = new Bundle();
    bundle.putString(AppUtils.LocationConstants.RESULT_DATA_KEY, message);
    bundle.putString(AppUtils.LocationConstants.LOCATION_DATA_AREA, address.getSubLocality());
    bundle.putString(AppUtils.LocationConstants.LOCATION_DATA_CITY, address.getLocality());
    bundle.putString(AppUtils.LocationConstants.LOCATION_DATA_STREET, address.getAddressLine(0));
    mReceiver.send(resultCode, bundle);
  } catch (Exception e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: owntracks/android

@Override
public String reverse(double latitude, double longitude) {
  if(!android.location.Geocoder.isPresent()) {
    Timber.e("geocoder is not present");
    return null;
  }
  List<Address> addresses;
  try {
    addresses = geocoder.getFromLocation(latitude, longitude, 1);
    if ((addresses != null) && (addresses.size() > 0)) {
      StringBuilder g = new StringBuilder();
      Address a = addresses.get(0);
      if (a.getAddressLine(0) != null)
        g.append(a.getAddressLine(0));
      return g.toString();
    } else {
      return "not available";
    }
  } catch (Exception e) {
    return null;
  }
}

代码示例来源:origin: zhaoyang21cn/iLiveSDK_Android_Suixinbo

private String getAddressFromLocation(Context context, Location location) {
  Geocoder geocoder = new Geocoder(context);
  try {
    double latitude = location.getLatitude();
    double longitude = location.getLongitude();
    SxbLog.d(TAG, "getAddressFromLocation->lat:" + latitude + ", long:" + longitude);
    List<Address> list = geocoder.getFromLocation(latitude, longitude, 1);
    if (list.size() > 0) {
      Address address = list.get(0);
      return address.getAddressLine(0);
    }
  } catch (IOException e) {
  }
  return "";
}

代码示例来源:origin: ankitdubey021/GPSTracker

private void fetchLocation(Location location) {
  List<Address> addresses;
  Geocoder geocoder = new Geocoder(ctx, Locale.getDefault());
  try {
    ADLocation adLocation=new ADLocation();
    addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
    adLocation.address= addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
    adLocation.city=addresses.get(0).getLocality();
    adLocation.state= addresses.get(0).getAdminArea();
    adLocation.country = addresses.get(0).getCountryName();
    adLocation.pincode= addresses.get(0).getPostalCode();
    adLocation.lat=location.getLatitude();
    adLocation.longi=location.getLongitude();
    locListener.whereIAM(adLocation);
  }catch (Exception e){
    e.printStackTrace();
  }
}

代码示例来源:origin: mitchtabian/Google-Maps-Google-Places

private void geoLocate(){
  Log.d(TAG, "geoLocate: geolocating");
  String searchString = mSearchText.getText().toString();
  Geocoder geocoder = new Geocoder(MapActivity.this);
  List<Address> list = new ArrayList<>();
  try{
    list = geocoder.getFromLocationName(searchString, 1);
  }catch (IOException e){
    Log.e(TAG, "geoLocate: IOException: " + e.getMessage() );
  }
  if(list.size() > 0){
    Address address = list.get(0);
    Log.d(TAG, "geoLocate: found a location: " + address.toString());
    //Toast.makeText(this, address.toString(), Toast.LENGTH_SHORT).show();
    moveCamera(new LatLng(address.getLatitude(), address.getLongitude()), DEFAULT_ZOOM,
        address.getAddressLine(0));
  }
}

代码示例来源:origin: andforce/iBeebo

@Override
protected String doInBackground(Void... params) {
  Geocoder geocoder = new Geocoder(AppMapActivity.this, Locale.getDefault());
  List<Address> addresses = null;
  try {
    addresses = geocoder.getFromLocation(geoBean.getLat(), geoBean.getLon(), 1);
  } catch (IOException e) {
    cancel(true);
  }
  if (addresses != null && addresses.size() > 0) {
    Address address = addresses.get(0);
    StringBuilder builder = new StringBuilder();
    int size = address.getMaxAddressLineIndex();
    for (int i = 0; i < size; i++) {
      builder.append(address.getAddressLine(i));
    }
    return builder.toString();
  }
  return "";
}

代码示例来源:origin: andforce/iBeebo

@Override
protected String doInBackground(Void... params) {
  Geocoder geocoder = new Geocoder(NearbyTimeLineActivity.this, Locale.getDefault());
  List<Address> addresses = null;
  try {
    addresses = geocoder.getFromLocation(geoBean.getLat(), geoBean.getLon(), 1);
  } catch (IOException e) {
    cancel(true);
  }
  if (addresses != null && addresses.size() > 0) {
    Address address = addresses.get(0);
    StringBuilder builder = new StringBuilder();
    int size = address.getMaxAddressLineIndex();
    for (int i = 0; i < size; i++) {
      builder.append(address.getAddressLine(i));
    }
    return builder.toString();
  }
  return "";
}

代码示例来源:origin: NightscoutFoundation/xDrip

public static String getStreetLocation(double latitude, double longitude) {
    try {
      final Geocoder geocoder = new Geocoder(xdrip.getAppContext(), Locale.getDefault());
      final List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);

      UserError.Log.d(TAG, addresses.toString());
      final String address = addresses.get(0).getAddressLine(0);
      UserError.Log.d(TAG, "Street address: " + address);
      return address;

    } catch (IndexOutOfBoundsException | NullPointerException e) {
      UserError.Log.e(TAG, "Couldn't isolate street address");
    } catch (IOException e) {
      UserError.Log.e(TAG, "Location error (reboot sometimes helps fix geocoding): " + e);

    }
    return null;

  }
}

代码示例来源:origin: jamorham/xDrip-plus

public static String getStreetLocation(double latitude, double longitude) {
    try {
      final Geocoder geocoder = new Geocoder(xdrip.getAppContext(), Locale.getDefault());
      final List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);

      UserError.Log.d(TAG, addresses.toString());
      final String address = addresses.get(0).getAddressLine(0);
      UserError.Log.d(TAG, "Street address: " + address);
      return address;

    } catch (IndexOutOfBoundsException | NullPointerException e) {
      UserError.Log.e(TAG, "Couldn't isolate street address");
    } catch (IOException e) {
      UserError.Log.e(TAG, "Location error (reboot sometimes helps fix geocoding): " + e);

    }
    return null;

  }
}

代码示例来源:origin: marzika/Snapprefs

@Override
  protected void onPostExecute(List<Address> addresses) {
    if (addresses == null || addresses.size() == 0) {
      Toast.makeText(getBaseContext(), "No Location found", Toast.LENGTH_SHORT).show();
    }
    // Adding Markers on Google Map for each matching address
    Address address = addresses.get(0);
    // Creating an instance of GeoPoint, to display in Google Map
    LatLng latLng = new LatLng(address.getLatitude(), address.getLongitude());
    String addressText = String.format("%s, %s",
        address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
        address.getCountryName());
    markerOptions = new MarkerOptions();
    markerOptions.position(latLng);
    markerOptions.title(addressText);
    map.addMarker(markerOptions);
    // Locate the first location
    map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 4));
  }
}

相关文章