<?xml version="1.0" encoding="utf-8"?
>
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="@+id/etAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter address"/>
<Button
android:id="@+id/btnGeocode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Geocode"/>
<EditText
android:id="@+id/etLatitude"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter latitude"/>
<EditText
android:id="@+id/etLongitude"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter longitude"/>
<Button
android:id="@+id/btnReverseGeocode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reverse Geocode"/>
<TextView
android:id="@+id/tvResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Result"/>
</LinearLayout>
[Link]
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
private EditText etAddress, etLatitude, etLongitude;
private TextView tvResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
etAddress = findViewById([Link]);
etLatitude = findViewById([Link]);
etLongitude = findViewById([Link]);
tvResult = findViewById([Link]);
Button btnGeocode = findViewById([Link]);
Button btnReverseGeocode = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View view) {
geocodeLocation([Link]().toString());
}
});
[Link](new [Link]() {
@Override
public void onClick(View view) {
double latitude =
[Link]([Link]().toString());
double longitude =
[Link]([Link]().toString());
reverseGeocodeLocation(latitude, longitude);
}
});
}
private void geocodeLocation(String locationName) {
Geocoder geocoder = new Geocoder(this, [Link]());
try {
List<Address> addresses = [Link](locationName,
1);
if (addresses != null && ![Link]()) {
Address address = [Link](0);
[Link]("Latitude: " + [Link]() + "\
nLongitude: " + [Link]());
} else {
[Link]("No location found");
}
} catch (IOException e) {
[Link]();
}
}
private void reverseGeocodeLocation(double latitude, double longitude) {
Geocoder geocoder = new Geocoder(this, [Link]());
try {
List<Address> addresses = [Link](latitude, longitude,
1);
if (addresses != null && ![Link]()) {
Address address = [Link](0);
[Link]("Address: " + [Link](0));
} else {
[Link]("No address found");
}
} catch (IOException e) {
[Link]();
}
}
}