当前位置: 首页>>代码示例>>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;未经允许,请勿转载。