0% found this document useful (0 votes)
122 views3 pages

Android Geocoding and Reverse Geocoding

Uploaded by

zyaaryan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views3 pages

Android Geocoding and Reverse Geocoding

Uploaded by

zyaaryan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

<?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]();
}
}
}

You might also like