I am working on development of android game application. I want to judge location of players of game. I want that details like pincode, city name,country name, geo cordinates, accuracy etc.
public class GPSLocationListener implements LocationListener {
Context context;
@Override
public void onLocationChanged(Location location2) {
location2.getLatitude();
location2.getLongitude();
@Override
public void onProviderDisabled(String provider) {
AlertPopup.displayPopup(context, "GPS Disabled");
}
@Override
public void onProviderEnabled(String provider) {
AlertPopup.displayPopup(context, "GPS Enabled");
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
but not able to get all data which i开发者_JS百科 want
Assuming that you are aware how to use GPS in android. Here is how to get the information you want.
Pincode, city name, country name
double latitude = location.getLatitude();
double longitude = location.getLongitude();
Geocoder gc = new Geocoder(this, Locale.getDefault());
try
{
List<Address> addresses = gc.getFromLocation(latitude,
longitude, 1);
StringBuilder sb = new StringBuilder();
if (addresses.size() > 0)
{
Address address = addresses.get(0);
for (int i = 0; i < address.getMaxAddressLineIndex(); i++)
sb.append(address.getAddressLine(i)).append("\n");
sb.append(address.getLocality()).append("\n");
sb.append(address.getPostalCode()).append("\n");
sb.append(address.getCountryName());
}
addressString = sb.toString();
} catch (IOException e) {
}
}
else
{
addressString = "No where";
}
Geo cordinates, accuracy
location.getLatitude()
and
location.getAccuracy()
精彩评论