private void updateWithNewLocation(Location location) { if (location != null) { double lat = location.getLatitude(); double lng = location.getLongitude(); Geocoder gc = new Geocoder(MainActivity.this, Locale.getDefault()); try { List<Address> addresses = gc.getFromLocation(lat, lng, 1); StringBuilder sb = new StringBuilder(); if (addresses.size() > 0) { Address address = addresses.get(0); String addressName = address.getSubLocality(); String firstCityName = address.getAdminArea(); infoToShow.locationName = StringProcessing.FilterStr(addressName); mAddressCityNameHan = infoToShow.locationName; locationCityName = infoToShow.locationName; // mAddressCityName = // CN2Pinyin.converterToSpell(infoToShow.locationName); mAdminArea = StringProcessing.FilterStr(firstCityName); sb.append(address.getLocality()) .append("/") .append(address.getSubLocality()) .append("\n"); } } catch (Exception e) { Log.d(e.toString(), "error!"); } } }
@Override public void run() { try { Location location = mLocation; GetLocation loc = new GetLocation(); _quname = loc.GetLocationFromLatLng(location.getLatitude(), location.getLongitude()); infoToShow.locationName = StringProcessing.FilterStr(_quname); mAddressCityName = CN2Pinyin.converterToSpell(infoToShow.locationName); getWeatherInfo(); } catch (Exception e) { return; } }