diff --git a/app/src/main/java/com/capstone/foodify/API/GoogleMapApi.java b/app/src/main/java/com/capstone/foodify/API/GoogleMapApi.java index 17c6676..4dff450 100644 --- a/app/src/main/java/com/capstone/foodify/API/GoogleMapApi.java +++ b/app/src/main/java/com/capstone/foodify/API/GoogleMapApi.java @@ -21,4 +21,7 @@ public interface GoogleMapApi { @GET("maps/api/geocode/json") Call getGeoCode(@Query("address") String address, @Query("key") String key); + + @GET("maps/api/geocode/json") + Call getAddress(@Query("latlng") String LatLng, @Query("key") String key); } diff --git a/app/src/main/java/com/capstone/foodify/Activity/OrderCheckOutActivity.java b/app/src/main/java/com/capstone/foodify/Activity/OrderCheckOutActivity.java index fd9bee6..c79a8f8 100644 --- a/app/src/main/java/com/capstone/foodify/Activity/OrderCheckOutActivity.java +++ b/app/src/main/java/com/capstone/foodify/Activity/OrderCheckOutActivity.java @@ -177,8 +177,7 @@ public class OrderCheckOutActivity extends AppCompatActivity { if(radio_button_selected == auto_detect_location){ //Action 2 - if(Common.CURRENT_LOCATION != null) - finalAddress = getAddress(); + } if(radio_button_selected == manual_input_address){ @@ -222,20 +221,27 @@ public class OrderCheckOutActivity extends AppCompatActivity { initZaloPaymentMethod(); } - private String getAddress() { - Geocoder geocoder = new Geocoder(OrderCheckOutActivity.this, Locale.getDefault()); - android.location.Address tempAddress; + private void getAddress() { + GoogleMapApi.apiService.getAddress(Common.CURRENT_LOCATION.getLatitude() + "," + Common.CURRENT_LOCATION.getLongitude(), Common.MAP_API).enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if(response.code() == 200){ + GoogleMapResponse responseData = response.body(); - try { - List addresses = geocoder.getFromLocation(Common.CURRENT_LOCATION.getLatitude(), Common.CURRENT_LOCATION.getLongitude(), 1); - tempAddress = addresses.get(0); - edt_address_detect.setText(tempAddress.getAddressLine(0)); + String address = responseData.getResults().get(0).getFormattedAddress(); - } catch (IOException e) { - throw new RuntimeException(e); - } + edt_address_detect.setText(address); + + finalAddress = address; + progress_layout.setVisibility(View.GONE); + } + } - return tempAddress.getAddressLine(0); + @Override + public void onFailure(Call call, Throwable t) { + Toast.makeText(OrderCheckOutActivity.this, "Lỗi kết nối!", Toast.LENGTH_SHORT).show(); + } + }); } @@ -562,7 +568,9 @@ public class OrderCheckOutActivity extends AppCompatActivity { manual_input_address_layout.setVisibility(View.GONE); //Reset address; - finalAddress = null; + progress_layout.setVisibility(View.VISIBLE); + if(Common.CURRENT_LOCATION != null) + getAddress(); } break; case R.id.manual_input_address: diff --git a/app/src/main/java/com/capstone/foodify/Common.java b/app/src/main/java/com/capstone/foodify/Common.java index 8615b86..ee3b847 100644 --- a/app/src/main/java/com/capstone/foodify/Common.java +++ b/app/src/main/java/com/capstone/foodify/Common.java @@ -40,7 +40,7 @@ import retrofit2.Response; public class Common { public static Location CURRENT_LOCATION = null; - public static final String MAP_API = "AIzaSyCR46ZE1kbE7zkTehhflB9jZgDjDT_2944"; + public static final String MAP_API = "AIzaSyAY14Ic32UP26Hg6GILznOfbBihiY5BUxw"; public static final String IS_FORGOT_PASSWORD = "isForgotPassword"; public static final String FORMAT_DATE="dd-MM-yyyy"; public static final String VALID_EMAIL_ADDRESS_REGEX = "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$";