gpsまたはネットワークを使用して、編集ボックスのボタンをクリックして現在の場所を取得しようとしています..チュートリアルや古い投稿で見つけたすべての可能な方法を試しました....しかし、私の場所は常にnullです..私はそうではありません? どこが間違っているのか。ネットワークはあるがインターネット/ gprsのない実際のデバイスでテストしています...
これは私が使用しているコードです..私はGPS_PROVIDERでも同じことを試しました..助けてください..
protected void showCurrentLocation()
{
geocoder = new Geocoder(this);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MINIMUM_TIME_BETWEEN_UPDATES,
MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
new MyLocationListener()
);
Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
System.out.println("loc.."+location);
if (location != null)
{
String message = String.format("Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude());
Toast.makeText(ShowActivity.this, message,
Toast.LENGTH_LONG).show();
//acTextView.setText(message);
try {
List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 10); //<10>
for (Address address : addresses) {
System.out.println("my location .."+address.getAddressLine(0));
acTextView.setText(address.getAddressLine(0));
}
} catch (IOException e) {
Log.e("LocateMe", "Could not get Geocoder data", e);
}
}
else
{
AlertDialog.Builder alertbox1 = new AlertDialog.Builder(this);
alertbox1.setMessage("No GPS or network ..Signal please fill the location manually!");
alertbox1.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1)
{}});
alertbox1.show();
}
}
新しい質問をするのではなく、質問を編集しているだけです..私の問題はまだ同じことに関連しているため...コードを何も変更していないため、これは現在完全に正常に機能しています.....しかし、問題GPS_PROVIDERを使用すると、経度と緯度の値とともに正確な住所が返されます..しかし、NETWORK_PROVIDERを使用すると、経度と緯度の値のみが返され、住所はありません... NETWORK_PROVIDERを使用して完全な住所を取得したい屋内ではGPSが機能しないため...どうすればいいですか?
ありがとう...!!