/**
* 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;
}
java类android.location.Address的实例源码
digiPune.java 文件源码
项目:FindX
阅读 36
收藏 0
点赞 0
评论 0
GeocodeObservable.java 文件源码
项目:GitHub
阅读 27
收藏 0
点赞 0
评论 0
@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);
}
}
}
ReverseGeocodeObservable.java 文件源码
项目:GitHub
阅读 22
收藏 0
点赞 0
评论 0
@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);
}
}
}
MainActivity.java 文件源码
项目:android-ponewheel
阅读 24
收藏 0
点赞 0
评论 0
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: ");
}
});
}
LocationAddress.java 文件源码
项目:Nibo
阅读 31
收藏 0
点赞 0
评论 0
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;
}
ChooseLocationActivity.java 文件源码
项目:BikeLine
阅读 22
收藏 0
点赞 0
评论 0
@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;
}
GPSTracker.java 文件源码
项目:FindX
阅读 25
收藏 0
点赞 0
评论 0
/**
* 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;
}
}
MyLocation.java 文件源码
项目:FindX
阅读 28
收藏 0
点赞 0
评论 0
/**
* 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;
}
}
PLocation.java 文件源码
项目:phonk
阅读 25
收藏 0
点赞 0
评论 0
@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;
}
GeocoderAdapter.java 文件源码
项目:civify-app
阅读 25
收藏 0
点赞 0
评论 0
@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;
}
GeocoderAdapter.java 文件源码
项目:civify-app
阅读 25
收藏 0
点赞 0
评论 0
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;
}
GeocoderAdapter.java 文件源码
项目:civify-app
阅读 28
收藏 0
点赞 0
评论 0
@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;
}
Authentication.java 文件源码
项目:BookED
阅读 30
收藏 0
点赞 0
评论 0
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();
}
}
FriendsAdapter.java 文件源码
项目:wheretomeet-android
阅读 23
收藏 0
点赞 0
评论 0
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;
}
SelectPositionActivity.java 文件源码
项目:MuslimMateAndroid
阅读 28
收藏 0
点赞 0
评论 0
@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;
}
SelectLocationTabsActivity.java 文件源码
项目:MuslimMateAndroid
阅读 31
收藏 0
点赞 0
评论 0
@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;
}
Utils.java 文件源码
项目:FlightSight-client
阅读 27
收藏 0
点赞 0
评论 0
public static String getLocalityNameEng(Context context, LatLng latLng) {
Geocoder gcd = new Geocoder(context, Locale.US);
try {
List<Address> addresses = gcd.getFromLocation(latLng.latitude, latLng.longitude, 1);
if (addresses.size() > 0) {
Address address = addresses.get(0);
String name = address.getCountryName();
if (address.getLocality() != null)
name = address.getLocality();
return name;
}
} catch (IOException ex) {
Log.d(TAG, Log.getStackTraceString(ex));
}
return null;
}
DefaultLocation.java 文件源码
项目:weex-3d-map
阅读 23
收藏 0
点赞 0
评论 0
/**
* 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;
}
MapLocationRequestTask.java 文件源码
项目:open-rmbt
阅读 34
收藏 0
点赞 0
评论 0
@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;
}
digiPune.java 文件源码
项目:FindX
阅读 33
收藏 0
点赞 0
评论 0
/**
* Try to get Postal Code
* @return null or postalCode
*/
public String getPostalCode(Context context)
{
List<Address> addresses = getGeocoderAddress(context);
if (addresses != null && addresses.size() > 0)
{
Address address = addresses.get(0);
String postalCode = address.getPostalCode();
return postalCode;
}
else
{
return null;
}
}
AddProfilFragment.java 文件源码
项目:ElephantAsia
阅读 28
收藏 0
点赞 0
评论 0
/**
* Set birth location from map
*
* @param location the location returned from the map picker
*/
public void setBirthLocation(Intent data) {
final Place place = PlacePicker.getPlace(getActivity(), data);
Geocoder geocoder = new Geocoder(getActivity());
try {
List<Address> addresses = geocoder.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1);
elephant.birthLoc.cityName = addresses.get(0).getAddressLine(0);
if (!addresses.get(0).getAddressLine(0).equals(addresses.get(0).getSubAdminArea())) {
elephant.birthLoc.districtName = addresses.get(0).getSubAdminArea();
}
elephant.birthLoc.provinceName = addresses.get(0).getAdminArea();
} catch (IOException e) {
e.printStackTrace();
}
birthLocation.setText(elephant.birthLoc.format());
}
EditRegistrationFragment.java 文件源码
项目:ElephantAsia
阅读 28
收藏 0
点赞 0
评论 0
public void setRegistrationLocation(Intent data) {
final Place place = PlacePicker.getPlace(getActivity(), data);
Geocoder geocoder = new Geocoder(getActivity());
try {
List<Address> addresses = geocoder.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1);
elephant.registrationLoc.cityName = addresses.get(0).getAddressLine(0);
if (!addresses.get(0).getAddressLine(0).equals(addresses.get(0).getSubAdminArea())) {
elephant.registrationLoc.districtName = addresses.get(0).getSubAdminArea();
}
elephant.registrationLoc.provinceName = addresses.get(0).getAdminArea();
} catch (IOException e) {
e.printStackTrace();
}
registrationLocation.setText(elephant.registrationLoc.format());
}
EditProfilFragment.java 文件源码
项目:ElephantAsia
阅读 28
收藏 0
点赞 0
评论 0
/**
* Set birth location from map
*
* @param location the location returned from the map picker
*/
public void setBirthLocation(Intent data) {
final Place place = PlacePicker.getPlace(getActivity(), data);
Geocoder geocoder = new Geocoder(getActivity());
try {
List<Address> addresses = geocoder.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1);
elephant.birthLoc.cityName = addresses.get(0).getAddressLine(0);
if (!addresses.get(0).getAddressLine(0).equals(addresses.get(0).getSubAdminArea())) {
elephant.birthLoc.districtName = addresses.get(0).getSubAdminArea();
}
elephant.birthLoc.provinceName = addresses.get(0).getAdminArea();
} catch (IOException e) {
e.printStackTrace();
}
birthLocation.setText(elephant.birthLoc.format());
}
ShortestDistance.java 文件源码
项目:iSPY
阅读 27
收藏 0
点赞 0
评论 0
private void getCompleteAddressString(double LATITUDE, double LONGITUDE) {
String strAdd = "";
Geocoder geocoder = new Geocoder(getApplicationContext());
try {
List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
String address = addresses.get(0).getAddressLine(0);
Log.i("address",address);
String city = addresses.get(0).getLocality();
Log.i("city",city);
String state = addresses.get(0).getAdminArea();
Log.i("state",state);
String country = addresses.get(0).getCountryName();
Log.i("country",country);
String postalCode = addresses.get(0).getPostalCode();
String knownName = addresses.get(0).getFeatureName();
add=address+", "+city+", "+state+", "+country;
} catch (Exception e) {
e.printStackTrace();
}
}
MyLocation.java 文件源码
项目:iSPY
阅读 28
收藏 0
点赞 0
评论 0
private void getCompleteAddressString(double LATITUDE, double LONGITUDE) {
String strAdd = "";
Geocoder geocoder = new Geocoder(getApplicationContext());
try {
List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
String address = addresses.get(0).getAddressLine(0);
Log.i("address",address);
String city = addresses.get(0).getLocality();
Log.i("city",city);
String state = addresses.get(0).getAdminArea();
Log.i("state",state);
String country = addresses.get(0).getCountryName();
Log.i("country",country);
String postalCode = addresses.get(0).getPostalCode();
String knownName = addresses.get(0).getFeatureName();
add=address+", "+city+", "+state+", "+country;
} catch (Exception e) {
e.printStackTrace();
}
}
MapsActivity.java 文件源码
项目:Android-Wear-Projects
阅读 33
收藏 0
点赞 0
评论 0
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;
}
LocationUtilities.java 文件源码
项目:CIA
阅读 25
收藏 0
点赞 0
评论 0
/**
* @param activity the activity requesting the location name
* @param location the device's current location
* @return the name of the device's current location if found, or LocationUtilities.NO_LOCATION_NAME otherwise
*/
public static String getLocationName(Activity activity, Location location){
String name = NO_LOCATION_NAME;
if (location != null) {
Geocoder geocoder = new Geocoder(activity);
try {
Address address = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1).get(0);
name = address.getThoroughfare();
} catch (IOException e) {
e.printStackTrace();
}
}
return name;
}
LocationUtils.java 文件源码
项目:GitHub
阅读 30
收藏 0
点赞 0
评论 0
/**
* 根据经纬度获取地理位置
*
* @param latitude 纬度
* @param longitude 经度
* @return {@link Address}
*/
public static Address getAddress(double latitude, double longitude) {
Geocoder geocoder = new Geocoder(Utils.getContext(), Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
if (addresses.size() > 0) return addresses.get(0);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
LocationUtils.java 文件源码
项目:RLibrary
阅读 30
收藏 0
点赞 0
评论 0
/**
* 根据经纬度获取地理位置
*
* @param latitude 纬度
* @param longitude 经度
* @return {@link Address}
*/
public static Address getAddress(double latitude, double longitude) {
Geocoder geocoder = new Geocoder(Utils.getContext(), Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
if (addresses.size() > 0) return addresses.get(0);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
FallbackReverseGeocodeObservable.java 文件源码
项目:GitHub
阅读 23
收藏 0
点赞 0
评论 0
@Override
public void call(Subscriber<? super List<Address>> subscriber) {
try {
subscriber.onNext(alternativeReverseGeocodeQuery());
subscriber.onCompleted();
} catch (Exception ex) {
subscriber.onError(ex);
}
}