use of android.location.Address in project NewXmPluginSDK by MiEcosystem.
the class XmPluginHostApi method reportGPSInfo.
/**
* ApiLevel:17 同步设备gps信息
*/
public void reportGPSInfo(final String did, final Callback<Void> callback) {
if (TextUtils.isEmpty(did)) {
if (callback != null) {
callback.onFailure(-1, "");
}
return;
}
final DeviceStat deviceStat = getDeviceByDid(did);
if (deviceStat == null) {
if (callback != null) {
callback.onFailure(-1, "");
}
return;
}
requestLocation(new Callback<Location>() {
@Override
public void onSuccess(Location location) {
if (location == null) {
if (callback != null) {
callback.onFailure(-1, "");
}
return;
}
Address lastAddress = null;
Geocoder geoCoder = new Geocoder(context());
try {
List<Address> addressList = geoCoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
if (addressList != null && addressList.size() > 0) {
lastAddress = addressList.get(0);
}
} catch (IOException e) {
}
if (lastAddress == null) {
if (callback != null) {
callback.onFailure(-1, "");
}
return;
}
String adminArea = "";
String countryCode = "";
String locality = "";
String thoroughfare = "";
String subLocality = "";
adminArea = lastAddress.getAdminArea();
countryCode = lastAddress.getCountryCode();
locality = lastAddress.getLocality();
thoroughfare = lastAddress.getThoroughfare();
subLocality = lastAddress.getSubLocality();
reportGPSInfo(deviceStat.model, did, location.getLongitude(), location.getLatitude(), adminArea, countryCode, locality, thoroughfare, subLocality, callback);
}
@Override
public void onFailure(int error, String errorInfo) {
if (callback != null) {
callback.onFailure(error, errorInfo);
}
}
});
}
use of android.location.Address in project WordPress-Android by wordpress-mobile.
the class GeocoderUtils method getAddressFromCoords.
public static Address getAddressFromCoords(Context context, double latitude, double longitude) {
Address address = null;
List<Address> addresses = null;
Geocoder gcd = getGeocoder(context);
if (gcd == null) {
return null;
}
try {
addresses = gcd.getFromLocation(latitude, longitude, 1);
} catch (IOException e) {
// may get "Unable to parse response from server" IOException here if Geocoder
// service is hit too frequently
AppLog.e(AppLog.T.UTILS, "Unable to parse response from server. Is Geocoder service hitting the server too frequently?", e);
}
// addresses may be null or empty if network isn't connected
if (addresses != null && addresses.size() > 0) {
address = addresses.get(0);
}
return address;
}
use of android.location.Address in project HumaneApp by Ganesh1010.
the class MapActivity method onMapSearch.
public void onMapSearch(String locations) {
System.out.println("location searched");
if (addresses.size() > 0)
addresses.clear();
//String locations = locationSearch.getText().toString();
try {
addresses = geocoder.getFromLocationName(locations, 1);
Address address = addresses.get(0);
if (mCurrLocationMarker != null) {
mCurrLocationMarker.remove();
}
latitude = address.getLatitude();
longitude = address.getLongitude();
location = new LatLng(latitude, longitude);
mCurrLocationMarker = mGoogleMap.addMarker(new MarkerOptions().position(location).title(getAaddress(latitude, longitude)));
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 17));
} catch (IOException e) {
e.printStackTrace();
}
}
use of android.location.Address in project HumaneApp by Ganesh1010.
the class GPSTracker method getPostalCode.
/**
* 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;
}
}
use of android.location.Address in project HumaneApp by Ganesh1010.
the class GPSTracker method getCountryName.
/**
* 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;
}
}
Aggregations