本文整理汇总了Java中android.location.Address.getAddressLine方法的典型用法代码示例。如果您正苦于以下问题:Java Address.getAddressLine方法的具体用法?Java Address.getAddressLine怎么用?Java Address.getAddressLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.location.Address
的用法示例。
在下文中一共展示了Address.getAddressLine方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAddress
import android.location.Address; //导入方法依赖的package包/类
public String getAddress(Context context, double lat, double lng) {
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
Address obj = addresses.get(0);
String add = obj.getAddressLine(0);
add = add + "," + obj.getAdminArea();
add = add + "," + obj.getCountryName();
return add;
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
return null;
}
}
示例2: formatAddress
import android.location.Address; //导入方法依赖的package包/类
@NonNull
private static String formatAddress(@NonNull Address address) {
String addressText = "";
String streetAndNumber = address.getAddressLine(0);
if (!(streetAndNumber == null || streetAndNumber.isEmpty())) {
addressText += streetAndNumber;
}
String locality = address.getLocality();
if (locality != null) {
if (!(addressText.isEmpty() || addressText.trim().endsWith(","))) {
addressText += ", ";
}
addressText += locality;
}
return addressText;
}
示例3: updateMemoryPosition
import android.location.Address; //导入方法依赖的package包/类
private void updateMemoryPosition(Memory memory, LatLng latLng) {
Geocoder geocoder = new Geocoder(this);
List<Address> matches = null;
try {
matches = geocoder.getFromLocation(latLng.latitude, latLng.longitude, 1);
} catch (IOException e) {
e.printStackTrace();
}
Address bestMatch = (matches.isEmpty()) ? null : matches.get(0);
int maxLine = bestMatch.getMaxAddressLineIndex();
memory.city = bestMatch.getAddressLine(maxLine - 1);
memory.country = bestMatch.getAddressLine(maxLine);
memory.latitude = latLng.latitude;
memory.longitude = latLng.longitude;
}
示例4: getAddressLine
import android.location.Address; //导入方法依赖的package包/类
/**
* 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;
}
}
示例5: call
import android.location.Address; //导入方法依赖的package包/类
@Override
public String call(Address address) {
if (address == null) return "";
String addressLines = "";
for (int i = 0; i <= address.getMaxAddressLineIndex(); i++) {
addressLines += address.getAddressLine(i) + '\n';
}
return addressLines;
}
示例6: getLocation
import android.location.Address; //导入方法依赖的package包/类
private void getLocation(Location location) {
Geocoder geocoder = new Geocoder(activity);
try {
List<Address> addresses = geocoder.getFromLocation(
location.getLatitude(), location.getLongitude(), 1);
Address address = addresses.get(0);
String result = address.getAddressLine(1) + address.getFeatureName();
Message message = handler.obtainMessage();
message.what = Configure.LOCATION_MESSAGE_CODE;
message.obj = result;
handler.sendMessage(message);
} catch (IOException e) {
e.printStackTrace();
}
}
示例7: addressToString
import android.location.Address; //导入方法依赖的package包/类
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();
}
示例8: getFromLocation
import android.location.Address; //导入方法依赖的package包/类
public String getFromLocation(double lat, double lng) {
String result = "";
List<Address> addresses = null;
try {
addresses = geocoder.getFromLocation(lat, lng, 1);
Address address = addresses.get(0);
for(int i = 0; i < address.getMaxAddressLineIndex(); i++) {
result += address.getAddressLine(i) + ", ";
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
示例9: onHandleIntent
import android.location.Address; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
Geocoder geoCoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = null;
resultReceiver = intent.getParcelableExtra(Constants.RECEIVER);
Location mLocation = intent.getParcelableExtra(Constants.LOCATION_DATA_EXTRA);
try {
addresses = geoCoder.getFromLocation(mLocation.getLatitude(), mLocation.getLongitude(), 1);
} catch (Exception e) {
Log.e(TAG, e.toString());
}
if (addresses == null || addresses.size() == 0) {
if (errorMessage.isEmpty()) {
errorMessage = "No address found";
Log.e(TAG, errorMessage);
}
deliverResultToReceiver(Constants.FAILURE_RESULT, errorMessage, null);
} else {
Address address = addresses.get(0);
String completeAddress = "";
for (int i = 1; i <= address.getMaxAddressLineIndex(); i++) {
completeAddress = completeAddress + (address.getAddressLine(i) + ",");
}
if (completeAddress != "") {
completeAddress=completeAddress.substring(0,completeAddress.length()-1);
}
deliverResultToReceiver(Constants.SUCCESS_RESULT, address.getAddressLine(0), completeAddress);
}
}
示例10: getAddressText
import android.location.Address; //导入方法依赖的package包/类
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;
}
示例11: getAddressHTMLText
import android.location.Address; //导入方法依赖的package包/类
@android.support.annotation.NonNull
public String getAddressHTMLText(Address addressObj) {
String address = addressObj.getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
String city = addressObj.getLocality();
String state = addressObj.getAdminArea();
String country = addressObj.getCountryName();
String postalCode = addressObj.getPostalCode();
String part1 = addressObj.getFeatureName();
String part2 = address + ", " + city + ", " + state + ", " + country + ", " + postalCode;
return "<b>" + part1 + "</b><label style='color:#ccc'> <br>" + part2 + "</label>";
}
示例12: getStreet
import android.location.Address; //导入方法依赖的package包/类
/**
* 根据经纬度获取所在街道
*
* @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);
}