私は現在の場所を見つける必要のあるアプリケーションを書きます。コードは緯度と経度を正しく戻していますが、実際のアドレス(逆ジオコーディング) が問題になることはありません。 誰かが助けてください、私はアンドロイドに新しいです。 私はonLocationChanged(所在地LOC)逆ジオコーディングが動作していません
void updateWithNewLocation(Location location)
{
if (location != null)
{
double lat = 29.00;//location.getLatitude();
double lng = 77.0;//location.getLongitude();
longitudeLattitudeString="Lattitude :"+lat+" Longitude :"+lng;
Geocoder gc = new Geocoder(this, Locale.getDefault());
try
{
List<Address> addresses = gc.getFromLocation(lat, lng, 1);
StringBuilder sb = new StringBuilder();
//Toast.makeText(this, "Problem1", 2000).show();
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");
Toast.makeText(this, "Problem2", 2000).show();
sb.append(address.getPostalCode()).append("\n");
sb.append(address.getCountryName());
}
else
{
addressString=" No Location";
//Toast.makeText(this, "Problem3", 2000).show();
}
addressString = sb.toString();
}
catch (IOException e)
{
//Toast.makeText(thisContext, "Problem : InCatch", 2000).show();
}
}
else
{
longitudeLattitudeString = "No location found";
}
}
ありがとうございましたjitendra私はそのことを知らなかった –
Googleプレイサービスの標準エミュレータで動作しますが、おそらくポストは古いです。 –