本文整理汇总了Java中android.location.Geocoder类的典型用法代码示例。如果您正苦于以下问题:Java Geocoder类的具体用法?Java Geocoder怎么用?Java Geocoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Geocoder类属于android.location包,在下文中一共展示了Geocoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLocationFromAddress
import android.location.Geocoder; //导入依赖的package包/类
/**
* to get latitude and longitude of an address
*
* @param strAddress address string
* @return lat and lng in comma separated string
*/
public String getLocationFromAddress(String strAddress) {
Geocoder coder = new Geocoder(mContext);
List<Address> address;
try {
address = coder.getFromLocationName(strAddress, 1);
if (address == null) {
return null;
}
Address location = address.get(0);
double lat = location.getLatitude();
double lng = location.getLongitude();
return lat + "," + lng;
} catch (Exception e) {
return null;
}
}
示例2: call
import android.location.Geocoder; //导入依赖的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);
}
}
}
示例3: getAddress
import android.location.Geocoder; //导入依赖的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;
}
}
示例4: getAddress
import android.location.Geocoder; //导入依赖的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;
}
示例5: getObservableAddressFromLocation
import android.location.Geocoder; //导入依赖的package包/类
public Observable<Address> getObservableAddressFromLocation(final double latitude, final double longitude,
final Context context) {
return new Observable<Address>() {
@Override
protected void subscribeActual(Observer<? super Address> observer) {
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);
observer.onNext(address);
}
} catch (IOException e) {
Log.e(TAG, "Unable connect to Geocoder", e);
}
}
}.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread());
}
示例6: call
import android.location.Geocoder; //导入依赖的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);
}
}
}
示例7: getLatLng
import android.location.Geocoder; //导入依赖的package包/类
public static Address getLatLng(String location, Context mContext) {
Address address = null;
try {
Geocoder gc = new Geocoder(mContext);
List<Address> addresses = gc.getFromLocationName(location, 1); // get the found Address Objects
for (Address a : addresses) {
if (a.hasLatitude() && a.hasLongitude()) {
// Log.i(TAG, String.valueOf(location + " " + a.getLatitude() + "
// " + a.getLongitude()));
address = a;
} else {
Log.d(TAG, " this location has no entry " + location);
}
}
} catch (IOException e) {
// handle the exception
}
return address;
}
示例8: doInBackground
import android.location.Geocoder; //导入依赖的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;
}
示例9: GetLoc
import android.location.Geocoder; //导入依赖的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();
}
}
示例10: onCreate
import android.location.Geocoder; //导入依赖的package包/类
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Utils.logD(LOG_TAG, "onCreate");
mSharedPreferences = new PreferencesManagerImp(getActivity().getApplicationContext());
mLocation = mSharedPreferences.getLocation();
if (savedInstanceState != null) {
mRotation = true;
}
LoaderProvider loaderProvider = new LoaderProvider(getContext());
LoaderManager loaderManager = getLoaderManager();
Geocoder geocoder = new Geocoder(getActivity());
// loaderManager.enableDebugLogging(true);
mPresenter = new FindPresenter(mLocation, loaderManager, loaderProvider, geocoder);
setHasOptionsMenu(true);
mRecentSearchSuggestions = new SearchRecentSuggestions(getContext(),
RecentSuggestionsProvider.AUTHORITY, RecentSuggestionsProvider.MODE);
mCompositeSubscription = new CompositeSubscription();
mActivityCoordinator = (CoordinatorLayout) getActivity().findViewById(R.id.coordinator);
mSnackCoordinator = (CoordinatorLayout) getActivity().findViewById(R.id.coordinatorSnackContainer);
}
示例11: onCreate
import android.location.Geocoder; //导入依赖的package包/类
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//mTm = new TimeMeasure(LOG_TAG);
Utils.logD(LOG_TAG, "onCreate:" + this);
mSharedPreferences = new PreferencesManagerImp(getActivity().getApplicationContext());
mLocation = mSharedPreferences.getLocation();
mGeocoder = new Geocoder(getActivity(), Locale.getDefault());
mLoaderProvider = new LoaderProvider(getActivity());
mLoaderManager = getLoaderManager();
mPresenter = new MapTabPresenter(mLoaderProvider, mLoaderManager, mGeocoder, mSharedPreferences);
mPresenter.setView(this);
mPresenter.setLocation(mLocation);
mAddress = mPresenter.onGetAddressFromLocation(mLocation);
}
示例12: getCompleteAddressString
import android.location.Geocoder; //导入依赖的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;
}
示例13: getCompleteAddressString
import android.location.Geocoder; //导入依赖的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;
}
示例14: getAddress
import android.location.Geocoder; //导入依赖的package包/类
/**
* get address info
*/
private Address getAddress(double latitude, double longitude) {
if(WXEnvironment.isApkDebugable()) {
WXLogUtils.d(TAG, "into--[getAddress] latitude:" + latitude + " longitude:" + longitude);
}
try {
if (mWXSDKInstance == null || mWXSDKInstance.isDestroy()) {
return null;
}
Geocoder gc = new Geocoder(mWXSDKInstance.getContext());
List<Address> list = gc.getFromLocation(latitude, longitude, 1);
if (list != null && list.size() > 0) {
return list.get(0);
}
} catch (Exception e) {
WXLogUtils.e(TAG, e);
}
return null;
}
示例15: doInBackground
import android.location.Geocoder; //导入依赖的package包/类
@Override
protected Address doInBackground(String... params) {
final Geocoder geocoder = new Geocoder(activity);
List<Address> addressList;
try {
addressList = geocoder.getFromLocationName(params[0], 1);
if (addressList != null && addressList.size() > 0) {
return addressList.get(0);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}