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


Java Address類代碼示例

本文整理匯總了Java中android.location.Address的典型用法代碼示例。如果您正苦於以下問題:Java Address類的具體用法?Java Address怎麽用?Java Address使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Address類屬於android.location包,在下文中一共展示了Address類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: call

import android.location.Address; //導入依賴的package包/類
@Override
public void call(Subscriber<? super List<Address>> subscriber) {
    Geocoder geocoder = new Geocoder(ctx);
    List<Address> result;

    try {
        if (bounds != null) {
            result = geocoder.getFromLocationName(locationName, maxResults, bounds.southwest.latitude, bounds.southwest.longitude, bounds.northeast.latitude, bounds.northeast.longitude);
        } else {
            result = geocoder.getFromLocationName(locationName, maxResults);
        }

        if (!subscriber.isUnsubscribed()) {
            subscriber.onNext(result);
            subscriber.onCompleted();
        }
    } catch (IOException e) {
        if (!subscriber.isUnsubscribed()) {
            subscriber.onError(e);
        }
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:GeocodeObservable.java

示例2: getAddress

import android.location.Address; //導入依賴的package包/類
private String getAddress(double lat, double lng) {

        String address=null;
        Geocoder geocoder = new Geocoder(context, Locale.getDefault());
        List<Address> list = null;
        try{
            list = geocoder.getFromLocation(lat, lng, 1);
        } catch(Exception e){
            e.printStackTrace();
        }
        if(list == null){
            System.out.println("Fail to get address from location");
            return null;
        }
        if(list.size() > 0){
            Address addr = list.get(0);
            address = removeNULL(addr.getAdminArea())+" "
                    + removeNULL(addr.getLocality()) + " "
                    + removeNULL(addr.getThoroughfare()) + " "
                    + removeNULL(addr.getFeatureName());
        }
        return address;
    }
 
開發者ID:ChristopherJdL,項目名稱:wheretomeet-android,代碼行數:24,代碼來源:FriendsAdapter.java

示例3: getGeocoderAddress

import android.location.Address; //導入依賴的package包/類
/**
 * Get list of address by latitude and longitude
 * @return null or List<Address>
 */
public List<Address> getGeocoderAddress(Context context)
{
    if (location != null)
    {
        Geocoder geocoder = new Geocoder(context, Locale.ENGLISH);
        try
        {
            List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
            return addresses;
        }
        catch (IOException e)
        {
            //e.printStackTrace();
            Log.e("Error : Geocoder", "Impossible to connect to Geocoder", e);
        }
    }

    return null;
}
 
開發者ID:SkylineLabs,項目名稱:FindX,代碼行數:24,代碼來源:digiPune.java

示例4: call

import android.location.Address; //導入依賴的package包/類
@Override
public void call(final Subscriber<? super List<Address>> subscriber) {
    Geocoder geocoder = new Geocoder(ctx, locale);
    try {
        subscriber.onNext(geocoder.getFromLocation(latitude, longitude, maxResults));
        subscriber.onCompleted();
    } catch (IOException e) {
        // If it's a service not available error try a different approach using google web api
        if (e.getMessage().equalsIgnoreCase("Service not Available")) {
            Observable
                    .create(new FallbackReverseGeocodeObservable(locale, latitude, longitude, maxResults))
                    .subscribeOn(Schedulers.io())
                    .subscribe(subscriber);
        } else {
            subscriber.onError(e);
        }
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:ReverseGeocodeObservable.java

示例5: startLocationScan

import android.location.Address; //導入依賴的package包/類
private void startLocationScan() {

        RxLocation rxLocation = new RxLocation(this);

        LocationRequest locationRequest = LocationRequest.create()
                .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
                .setInterval(TimeUnit.SECONDS.toMillis(5));

        rxLocationObserver = rxLocation.location()
                .updates(locationRequest)
                .subscribeOn(Schedulers.io())
                .flatMap(location -> rxLocation.geocoding().fromLocation(location).toObservable())
                .observeOn(Schedulers.io())
                .subscribeWith(new DisposableObserver<Address>() {
                    @Override public void onNext(Address address) {

                        boolean isLocationsEnabled = App.INSTANCE.getSharedPreferences().isLocationsEnabled();
                        if (isLocationsEnabled) {
                            mOWDevice.setGpsLocation(address);
                        } else if (rxLocationObserver != null) {
                            rxLocationObserver.dispose();
                        }
                    }

                    @Override public void onError(Throwable e) {
                        Log.e(TAG, "onError: error retreiving location", e);
                    }

                    @Override public void onComplete() {
                        Log.d(TAG, "onComplete: ");
                    }
                });
    }
 
開發者ID:ponewheel,項目名稱:android-ponewheel,代碼行數:34,代碼來源:MainActivity.java

示例6: getAddressFromLocation

import android.location.Address; //導入依賴的package包/類
public Address getAddressFromLocation(final double latitude, final double longitude,
                                      final Context context) {

    Geocoder geocoder = new Geocoder(context, Locale.getDefault());

    try {
        List<Address> addressList = geocoder.getFromLocation(
                latitude, longitude, 1);
        if (addressList != null && addressList.size() > 0) {
            address = addressList.get(0);

        }
    } catch (IOException e) {
        Log.e(TAG, "Unable connect to Geocoder", e);
    }
    return address;


}
 
開發者ID:aliumujib,項目名稱:Nibo,代碼行數:20,代碼來源:LocationAddress.java

示例7: onQueryTextSubmit

import android.location.Address; //導入依賴的package包/類
@Override
public boolean onQueryTextSubmit(String query) {
    if(query.length() == 0)
        return false;
    // get location from api
    Geocoder geocoder = new Geocoder(this);
    List<Address> addresses;
    try {
        addresses = geocoder.getFromLocationName(query, 1);
    } catch (IOException e) {
        return true;
    }
    if(addresses.size() > 0) {
        searchPosition = new LatLng(addresses.get(0).getLatitude(), addresses.get(0).getLongitude());
    } else {
        // no result was found
        Toast.makeText(this, getString(R.string.no_result), Toast.LENGTH_SHORT).show();
        searchPosition = null;
        return true;
    }
    searchView.clearFocus();
    searchHistory.add(query);
    updateNowLocation(searchPosition, getString(R.string.choose_location_tag), true);
    return true;
}
 
開發者ID:w86763777,項目名稱:BikeLine,代碼行數:26,代碼來源:ChooseLocationActivity.java

示例8: getCountryName

import android.location.Address; //導入依賴的package包/類
/**
 * Try to get CountryName
 * @return null or postalCode
 */
public String getCountryName(Context context)
{
    List<Address> addresses = getGeocoderAddress(context);
    if (addresses != null && addresses.size() > 0)
    {
        Address address = addresses.get(0);
        String countryName = address.getCountryName();

        return countryName;
    }
    else
    {
        return null;
    }
}
 
開發者ID:SkylineLabs,項目名稱:FindX,代碼行數:20,代碼來源:GPSTracker.java

示例9: getLocality

import android.location.Address; //導入依賴的package包/類
/**
 * Try to get Locality
 * @return null or locality
 */
public String getLocality(Context context)
{
    List<Address> addresses = getGeocoderAddress(context);
    if (addresses != null && addresses.size() > 0)
    {
        Address address = addresses.get(0);
        String locality = address.getLocality();

        return locality;
    }
    else
    {
        return null;
    }
}
 
開發者ID:SkylineLabs,項目名稱:FindX,代碼行數:20,代碼來源:MyLocation.java

示例10: getLocationName

import android.location.Address; //導入依賴的package包/類
@ProtoMethod(description = "Get the location name of a given latitude and longitude", example = "")
@ProtoMethodParam(params = {"latitude", "longitude"})
public String getLocationName(double lat, double lon) {
    String gpsLocation = "";
    Geocoder gcd = new Geocoder(getContext(), Locale.getDefault());
    List<Address> addresses;
    try {
        addresses = gcd.getFromLocation(lat, lon, 1);
        gpsLocation = addresses.get(0).getLocality();

    } catch (IOException e) {
        e.printStackTrace();
    }

    return gpsLocation;
}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:17,代碼來源:PLocation.java

示例11: doInBackground

import android.location.Address; //導入依賴的package包/類
@Nullable
@Override
protected Address doInBackground(String... strings) {
    Geocoder geocoder = new Geocoder(mContext, Locale.getDefault());
    Address result = null;
    double latitude = mLocation.getLatitude();
    double longitude = mLocation.getLongitude();
    try {
        List<Address> geocodedAddresses = geocoder.getFromLocation(latitude, longitude, 1);
        if (geocodedAddresses != null && !geocodedAddresses.isEmpty()) {
            result = geocodedAddresses.get(0);
        }
    } catch (IOException e) {
        Throwable cause = e.getCause();
        Log.i(TAG, "Error " + (cause != null ? cause.getClass().getSimpleName()
                : '(' + e.getClass().getSimpleName() + ": " + e.getMessage() + ')')
                + " getting locality with Geocoder. "
                + "Trying with HTTP/GET on Google Maps API.");
        result = geolocateFromGoogleApis(latitude, longitude);
    }
    return result;
}
 
開發者ID:ArnauBlanch,項目名稱:civify-app,代碼行數:23,代碼來源:GeocoderAdapter.java

示例12: geolocateFromGoogleApis

import android.location.Address; //導入依賴的package包/類
private Address geolocateFromGoogleApis(double latitude, double longitude) {
    String url = "https://maps.googleapis.com/maps/api/geocode/json?latlng="
            + latitude + ',' + longitude + "&sensor=true&language="
            + Locale.getDefault().getLanguage();
    OkHttpClient client = new OkHttpClient();
    Request request = new Request.Builder().url(url).build();
    Response response = null;
    ResponseBody responseBody = null;
    try {
        // Synchronous call because we're already on a background thread behind UI
        response = client.newCall(request).execute();
        responseBody = response.body();
        String jsonData = responseBody.string();
        if (response.isSuccessful()) return getAddressFromGoogleApis(jsonData);
        mErrorMessage = mContext.getString(R.string.unexpected_code)
                + mContext.getString(R.string.on_google) + response.code();
    } catch (IOException | JSONException e) {
        mErrorMessage = mContext.getString(R.string.error_locality);
        mError = e;
    } finally {
        if (response != null) response.close();
        if (responseBody != null) responseBody.close();
    }
    return null;
}
 
開發者ID:ArnauBlanch,項目名稱:civify-app,代碼行數:26,代碼來源:GeocoderAdapter.java

示例13: 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;
}
 
開發者ID:ArnauBlanch,項目名稱:civify-app,代碼行數:17,代碼來源:GeocoderAdapter.java

示例14: GetLoc

import android.location.Address; //導入依賴的package包/類
public void GetLoc(final String firstname, final String lastname, final String em, final String pass, String loc,String phone, final SharedPreferences sharedPref)
{

    Geocoder coder = new Geocoder(Authentication.this);
    List<Address> addresses;
    try {
        addresses = coder.getFromLocationName(loc, 5);
        if (addresses == null) {
        }
        Address location = addresses.get(0);
        double lat = location.getLatitude();
        double lng = location.getLongitude();
        Log.i("Lat",""+lat);
        Log.i("Lng",""+lng);
        //SetData(firstname,lastname,em,pass,loc,lat,lng,phone,sharedPref);

    } catch (IOException e) {
        e.printStackTrace();
    }


}
 
開發者ID:prabhavgupta,項目名稱:BookED,代碼行數:23,代碼來源:Authentication.java

示例15: 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


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