本文整理汇总了Java中android.location.Address.getMaxAddressLineIndex方法的典型用法代码示例。如果您正苦于以下问题:Java Address.getMaxAddressLineIndex方法的具体用法?Java Address.getMaxAddressLineIndex怎么用?Java Address.getMaxAddressLineIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.location.Address
的用法示例。
在下文中一共展示了Address.getMaxAddressLineIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCompleteAddressString
import android.location.Address; //导入方法依赖的package包/类
@SuppressLint("LongLogTag")
private String getCompleteAddressString(double LATITUDE, double LONGITUDE) {
String strAdd = "";
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
if (addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder("");
for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
}
strAdd = strReturnedAddress.toString();
Log.w("My Current loction address", "" + strReturnedAddress.toString());
} else {
Log.w("My Current loction address", "No Address returned!");
}
} catch (Exception e) {
e.printStackTrace();
Log.w("My Current loction address", "Canont get Address!");
}
return strAdd;
}
示例2: getCompleteAddressString
import android.location.Address; //导入方法依赖的package包/类
@SuppressLint("LongLogTag")
private String getCompleteAddressString(double LATITUDE, double LONGITUDE) {
String strAdd = "";
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
if (addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder("");
for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
}
strAdd = strReturnedAddress.toString();
Log.w("My Current loction address", "" + strReturnedAddress.toString());
} else {
Log.w("My Current loction address", "No Address returned!");
}
} catch (Exception e) {
e.printStackTrace();
Log.w("My Current loction address", "Canont get Address!");
}
return strAdd;
}
示例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: onPostExecute
import android.location.Address; //导入方法依赖的package包/类
@Override
protected void onPostExecute(Address address) {
if (address == null)
return;
StringBuilder builder = new StringBuilder();
if (address.getMaxAddressLineIndex() >= 0)
builder.append(address.getAddressLine(0));
if (address.getLocality() != null) {
builder.append(", ");
builder.append(address.getLocality());
}
locationString = builder.toString();
Intent intent = new Intent(LOCATION_CHANGED_ACTION);
intent.putExtra(EXTRA_LOCATION, location);
intent.putExtra(EXTRA_GEOCODE, locationString);
localBroadcastManager.sendBroadcast(intent);
}
示例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: onGetAddressFromLocation
import android.location.Address; //导入方法依赖的package包/类
@Override
public void onGetAddressFromLocation(Location currentLocation) {
List<Address> addresses = null;
try {
addresses = mGeocoder.getFromLocation(
currentLocation.getLatitude(),
currentLocation.getLongitude(),
1);
} catch (IOException ioe) {
}
if (addresses == null || addresses.size() == 0) {
Utils.logD(LOG_TAG, "no address found");
mView.setAddress(null);
} else {
Address address = addresses.get(0);
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
stringBuilder.append(address.getAddressLine(i));
if (i != address.getMaxAddressLineIndex() - 1) {
stringBuilder.append(Constants.COMMA);
}
}
Utils.logD(LOG_TAG, "address found");
mView.setAddress(stringBuilder.toString());
}
}
示例7: onGetAddressFromLocation
import android.location.Address; //导入方法依赖的package包/类
@Override
public String onGetAddressFromLocation(Location currentLocation) {
List<Address> addresses = null;
try {
addresses = mGeocoder.getFromLocation(
currentLocation.getLatitude(),
currentLocation.getLongitude(),
1);
} catch (IOException ioe) {
}
if (addresses == null || addresses.size() == 0) {
Utils.logD(LOG_TAG, "no address found");
return null;
} else {
Address address = addresses.get(0);
StringBuilder stringBuilder = new StringBuilder();
// Fetch the address lines using getAddressLine,
// join them, and send them to the thread.
for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
if (i == 0) {
preferencesManager.saveStreet(address.getAddressLine(i));
}
stringBuilder.append(address.getAddressLine(i));
if (i != address.getMaxAddressLineIndex() - 1) {
stringBuilder.append(Constants.COMMA);
}
}
Utils.logD(LOG_TAG, "address found");
mAddress = stringBuilder.toString();
return mAddress;
}
}
示例8: onGetAddressFromLocation
import android.location.Address; //导入方法依赖的package包/类
public String onGetAddressFromLocation(Location currentLocation) {
List<Address> addresses = null;
try {
addresses = mGeocoder.getFromLocation(
currentLocation.getLatitude(),
currentLocation.getLongitude(),
1);
} catch (IOException ioe) {
}
if (addresses == null || addresses.size() == 0) {
Utils.logD(LOG_TAG, "no address found");
return mLocation.getLatitude() + Constants.COMMA + mLocation.getLongitude();
} else {
Address address = addresses.get(0);
StringBuilder stringBuilder = new StringBuilder();
// Fetch the address lines using getAddressLine,
// join them, and send them to the thread.
for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
stringBuilder.append(address.getAddressLine(i));
if (i != address.getMaxAddressLineIndex() - 1) {
stringBuilder.append(Constants.COMMA);
}
}
Utils.logD(LOG_TAG, "address found");
return stringBuilder.toString();
}
}
示例9: locationToAddress
import android.location.Address; //导入方法依赖的package包/类
public boolean locationToAddress(double latitude, double longitude) {
Geocoder geocoder = new Geocoder(this.context, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
if (addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder("");
locationInfo.clear();
String city = returnedAddress.getAdminArea();
if(city==null) city = returnedAddress.getLocality();
locationInfo.put("country", returnedAddress.getCountryName());
locationInfo.put("countrycode", returnedAddress.getCountryCode().toLowerCase());
locationInfo.put("latitude", ""+returnedAddress.getLatitude());
locationInfo.put("longitude", ""+returnedAddress.getLongitude());
if(city!=null)locationInfo.put("city", ""+city);
String address = "";
for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
address = address + returnedAddress.getAddressLine(i) + "\n";
}
locationInfo.put("address", address);
return true;
} else {
}
} catch (Exception e) {
}
return false;
}
示例10: 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;
}
示例11: 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);
}
}
示例12: 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;
}
示例13: CurrentAddress
import android.location.Address; //导入方法依赖的package包/类
/**
* Provides a textual representation of the current address or
* "No address available".
*/
@SimpleProperty(category = PropertyCategory.BEHAVIOR)
public String CurrentAddress() {
if (hasLocationData &&
latitude <= 90 && latitude >= -90 &&
longitude <= 180 || longitude >= -180) {
try {
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
if (addresses != null && addresses.size() == 1) {
Address address = addresses.get(0);
if (address != null) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i <= address.getMaxAddressLineIndex(); i++) {
sb.append(address.getAddressLine(i));
sb.append("\n");
}
return sb.toString();
}
}
} catch (Exception e) {
// getFromLocation can throw an IOException or an IllegalArgumentException
// a bad result can give an indexOutOfBoundsException
// are there others?
if (e instanceof IllegalArgumentException
|| e instanceof IOException
|| e instanceof IndexOutOfBoundsException ) {
Log.e("LocationSensor", "Exception thrown by getting current address " + e.getMessage());
} else {
// what other exceptions can happen here?
Log.e("LocationSensor",
"Unexpected exception thrown by getting current address " + e.getMessage());
}
}
}
return "No address available";
}
示例14: 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();
}
示例15: doInBackground
import android.location.Address; //导入方法依赖的package包/类
@Override
protected String doInBackground(Location... params) {
// Set up the geocoder
Geocoder geocoder = new Geocoder(MainActivity.this,
Locale.getDefault());
// Get the passed in location
Location location = params[0];
List<Address> addresses = null;
String resultMessage = "";
try {
addresses = geocoder.getFromLocation(
location.getLatitude(),
location.getLongitude(),
// In this sample, get just a single address
1);
} catch (IOException ioException) {
// Catch network or other I/O problems
resultMessage = MainActivity.this
.getString(R.string.service_not_available);
Log.e(TAG, resultMessage, ioException);
} catch (IllegalArgumentException illegalArgumentException) {
// Catch invalid latitude or longitude values
resultMessage = MainActivity.this
.getString(R.string.invalid_lat_long_used);
Log.e(TAG, resultMessage + ". " +
"Latitude = " + location.getLatitude() +
", Longitude = " +
location.getLongitude(), illegalArgumentException);
}
// If no addresses found, print an error message.
if (addresses == null || addresses.size() == 0) {
if (resultMessage.isEmpty()) {
resultMessage = MainActivity.this
.getString(R.string.no_address_found);
Log.e(TAG, resultMessage);
}
} else {
// If an address is found, read it into resultMessage
Address address = addresses.get(0);
ArrayList<String> addressFragments = new ArrayList<>();
// Fetch the address lines using getAddressLine,
// join them, and send them to the thread
for (int i = 0; i <= address.getMaxAddressLineIndex(); i++) {
addressFragments.add(address.getAddressLine(i));
}
resultMessage = TextUtils.join(
System.getProperty("line.separator"),
addressFragments);
}
return resultMessage;
}