當前位置: 首頁>>代碼示例>>Java>>正文


Java Address.getMaxAddressLineIndex方法代碼示例

本文整理匯總了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;
}
 
開發者ID:fekracomputers,項目名稱:MuslimMateAndroid,代碼行數:25,代碼來源:SelectPositionActivity.java

示例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;
}
 
開發者ID:fekracomputers,項目名稱:MuslimMateAndroid,代碼行數:26,代碼來源:SelectLocationTabsActivity.java

示例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;
}
 
開發者ID:PacktPublishing,項目名稱:Android-Wear-Projects,代碼行數:17,代碼來源:MapsActivity.java

示例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);
}
 
開發者ID:gvinciguerra,項目名稱:custode,代碼行數:20,代碼來源:LocationService.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:AddressToStringFunc.java

示例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());
    }

}
 
開發者ID:cahergil,項目名稱:Farmacias,代碼行數:31,代碼來源:ListTabPresenter.java

示例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;
    }


}
 
開發者ID:cahergil,項目名稱:Farmacias,代碼行數:40,代碼來源:MapTabPresenter.java

示例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();
    }

}
 
開發者ID:cahergil,項目名稱:Farmacias,代碼行數:33,代碼來源:FindPresenter.java

示例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;
    }
 
開發者ID:fekracomputers,項目名稱:MuslimMateAndroid,代碼行數:36,代碼來源:LocationReader.java

示例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;
}
 
開發者ID:micromasterandroid,項目名稱:androidadvanced,代碼行數:16,代碼來源:Util.java

示例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);
    }

}
 
開發者ID:pmathew92,項目名稱:MapsWithPlacesAutoComplete,代碼行數:34,代碼來源:GeoCoderIntentService.java

示例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;
}
 
開發者ID:florent37,項目名稱:RxGps,代碼行數:14,代碼來源:MainActivity.java

示例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";
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:41,代碼來源:LocationSensor.java

示例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();
}
 
開發者ID:tiberiusteng,項目名稱:financisto1-holo,代碼行數:13,代碼來源:AddressGeocoder.java

示例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;
}
 
開發者ID:ngamolsky,項目名稱:WalkMyAndroid-Location,代碼行數:59,代碼來源:MainActivity.java


注:本文中的android.location.Address.getMaxAddressLineIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。