我正在开发Android游戏应用程序。我想判断游戏玩家的位置。我想要像pincode,城市名称,国家名称,地理坐标,准确性等细节。
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;
}
}
但无法获取我想要的所有数据
答案 0 :(得分:1)
假设您知道如何在Android中使用GPS。以下是获取所需信息的方法。
Pincode,城市名称,国家/地区名称
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";
}
地理坐标,准确性
location.getLatitude()
和
location.getAccuracy()