private String getCity() {
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
if (addresses != null) {
Address returnedAddress = addresses.get(0);
city = returnedAddress.getAdminArea().toString();
} else {
city = "Error";
}
} catch (IOException e) {
e.printStackTrace();
city = "Error";
}
return city;
}
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginRight="16dp"
android:layout_marginBottom="40dp"
app:borderWidth="0dp"
app:elevation="6dp"
app:backgroundTint="@color/IDЦвета"
app:srcCompat="@drawable/IDТвоейИконки"
android:layout_marginEnd="16dp" />
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(final String query) {
//вызовется при нажатии на лупу на клавиатуре
return false;
}
@Override
public boolean onQueryTextChange(final String newText) {
//вызовется при изменении ведённого текста
return true;
}
});
public String ServerQuery() throws IOException {
OkHttpClient client = new OkHttpClient();
String json = getJson();
RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);
Request request = new Request.Builder()
.url(getUrl())
.put(body)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
return null;
}
if (Looper.myLooper() == null){
Looper.prepare();
}
private void refreshUserCoordinates(final Context contextThread) {
Intent intent = getIntent();
final String user = intent.getStringExtra("user");
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
if (Looper.myLooper() == null)
{
Looper.prepare();
}
GeoPosition geoPosition = new GeoPosition();
geoPosition.SetUpLocationListener(contextThread);
ServerInteraction serverInteraction = new ServerInteraction("http://razdvatri.ru/refreshCoordinates.php",
"{\"user\" " + ":\"" + user + "\", \"latitude\" " + ":\"" + geoPosition.getLatitude() + "\", \"longitude\" :" + "\"" + geoPosition.getLongitude() + "\"" + "}", "put");
serverInteraction.execute();
}
}, 0L, 50L * 1000);
}