-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGeoAcordctivity.java
42 lines (35 loc) · 1.43 KB
/
GeoAcordctivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.puddlesmanagment;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
public class GeoAcordctivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_geo_acordctivity);
getAddress(19.2280091,72.8580217);
}
private String getAddress(double latitude, double longitude) {
StringBuilder result = new StringBuilder();
try {
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
if (addresses.size() > 0) {
Address address = addresses.get(0);
result.append(address.getAddressLine(0)).append("\n");
result.append(address.getPostalCode()).append("\n");
result.append(address.getSubLocality()).append("\n");
result.append(address.getCountryCode()).append("\n");
result.append(address.getCountryName());
}
} catch (IOException e) {
Log.e("tag", e.getMessage());
}
return result.toString();
}
}