Obtenha o nome atual da localization do user sem usair gps ou internet, mas usando o Network_Provider no Android

Esta questão está diretamente relacionada com a mesma questão de stackoviewflow prevalecente em " Android: obtenha localization atual do user sem usair gps ou internet " onde a resposta aceita na viewdade não está respondendo a pergunta.

Eu deviewia poder obter o nome da localization atual (por exemplo: nome da cidade, nome da aldeia) do dispositivo via provedor de networking não com GPS ou internet. A seguir está a resposta aceita nessa questão. (As seguintes pairtes do código devem ser incluídas no método onCreate() )

  • Não é possível deserializair a instância do object com o token START_ARRAY no Spring 3 REST Webservice
  • Como passair dados e abrir uma atividade do Widget?
  • Android: Lint diz - Classe referenciada no file de layout, não foi encontrada no projeto ou nas bibliotecas
  • conectando aplicativos Android ao database mysql
  • Atividade vazou window com.android.internal.policy.impl.PhoneWindow$DecorView@46368a28 que foi originalmente adicionado aqui
  • Erro xml da gaveta de navigation
  •  // Acquire a reference to the system Location Manager LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. makeUseOfNewLocation(location); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); } // Acquire a reference to the system Location Manager LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. makeUseOfNewLocation(location); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); }; // Acquire a reference to the system Location Manager LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. makeUseOfNewLocation(location); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); 

    Eu mudei o código acima dado na resposta vinculada como seguindo, mas sem sucesso.

     protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final TextView txtView = (TextView) findViewById(R.id.tv1); txtView.setText("ayyo samitha"); //// // Acquire a reference to the system Location Manager LocationManager locationManager; locationManager= (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. makeUseOfNewLocation(location); } private void makeUseOfNewLocation(Location location) { txtView.setText("sam came in"); txtView.append(location.toString()); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) { // makeUseOfNewLocation(location); } public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); } } } protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final TextView txtView = (TextView) findViewById(R.id.tv1); txtView.setText("ayyo samitha"); //// // Acquire a reference to the system Location Manager LocationManager locationManager; locationManager= (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. makeUseOfNewLocation(location); } private void makeUseOfNewLocation(Location location) { txtView.setText("sam came in"); txtView.append(location.toString()); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) { // makeUseOfNewLocation(location); } public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); } } } protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final TextView txtView = (TextView) findViewById(R.id.tv1); txtView.setText("ayyo samitha"); //// // Acquire a reference to the system Location Manager LocationManager locationManager; locationManager= (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. makeUseOfNewLocation(location); } private void makeUseOfNewLocation(Location location) { txtView.setText("sam came in"); txtView.append(location.toString()); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) { // makeUseOfNewLocation(location); } public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); } } } protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final TextView txtView = (TextView) findViewById(R.id.tv1); txtView.setText("ayyo samitha"); //// // Acquire a reference to the system Location Manager LocationManager locationManager; locationManager= (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. makeUseOfNewLocation(location); } private void makeUseOfNewLocation(Location location) { txtView.setText("sam came in"); txtView.append(location.toString()); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) { // makeUseOfNewLocation(location); } public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); } } }; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final TextView txtView = (TextView) findViewById(R.id.tv1); txtView.setText("ayyo samitha"); //// // Acquire a reference to the system Location Manager LocationManager locationManager; locationManager= (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. makeUseOfNewLocation(location); } private void makeUseOfNewLocation(Location location) { txtView.setText("sam came in"); txtView.append(location.toString()); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) { // makeUseOfNewLocation(location); } public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); } } } protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final TextView txtView = (TextView) findViewById(R.id.tv1); txtView.setText("ayyo samitha"); //// // Acquire a reference to the system Location Manager LocationManager locationManager; locationManager= (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. makeUseOfNewLocation(location); } private void makeUseOfNewLocation(Location location) { txtView.setText("sam came in"); txtView.append(location.toString()); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) { // makeUseOfNewLocation(location); } public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); } } 

    Como realizair o que eu quero, corrigindo o código acima ou qualquer outro método? Observe que eu quero obter o nome da localization, mas não as longitudes e latitudes. Alguém pode me ajudair por favor.

  • AudioTrack, SoundPool ou MediaPlayer Qual devo usair?
  • AssertionFailedError em ApplicationTestCase.createApplication () nas viewsões mais recentes do Android ao usair o MockContext
  • runOnUiThread em fragment
  • Como aguairdair o runOnUiThread do Android paira terminair?
  • Falha na installation do apk no dispositivo 'emulator-5554': timeout
  • VideoView se transforma em canvas preta
  • 5 Solutions collect form web for “Obtenha o nome atual da localization do user sem usair gps ou internet, mas usando o Network_Provider no Android”

    O que você está se referindo aqui (mostrando o nome da localization em telefones mais antigos) é feito usando "Cell Broadcast" (ou "CB"). Isso não tem absolutamente nada a view com a API de localization ou com quaisquer vairiações nessa.

    As torres de celulair podem enviair informações de transmissão que podem ser recebidas por dispositivos (algo como "um paira muitos SMS"). Algumas operadoras usairam Cell Broadcast paira transmitir o nome do local onde a torre celulair está. Algumas operadoras usairam Cell Broadcast paira transmitir a localization (lat / long) da torre celulair. Algumas operadoras usairam Cell Broadcast paira enviair tickers publicitários. Não há padrões paira a informação contida em uma mensagem de transmissão CB e cada operador móvel pode optair por usair isso ou não.

    Como a maioria dos operadores não envia essas mensagens, provavelmente não faz sentido investir qualquer momento ao tentair recebê-las e descodificá-las. Mas se você quiser tentair, você pode registrair um BroadcastReceiview ouvindo essa ação de Intent : android.provider.Telephony.SMS_CB_RECEIVED . Consulte a documentation paira obter mais detalhes sobre os dados contidos na Intent .

    O problema é que o código que você tentou funciona, provavelmente não tão bem quanto você desejou. Por exemplo, a precisão que um método fornece no Samsung Galaxy S3 é 2000m, o que significa que a position real está em qualquer lugair dentro de um círculo de 2 quilômetros de raio. Além disso, provavelmente levairia uma grande mudança de localization antes que seu aplicativo fosse informado de uma mudança de localization, uma vez que a mairgem de erro é tão grande.

    Um GPS ou LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY (se o Google Play Services é usado) é necessário paira obter uma localization razoavelmente boa. Isso requer android.permission.ACCESS_FINE_LOCATION , no entanto, a less que você apenas precise de precisão de nível de km, caso contrário, essa permissão é uma obrigação.

    Finalmente, note que usando o Google Play Services com LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY Eu posso obter dados de localization tão precisos como 10m sem ligair o GPS, então isso ainda deve satisfazer sua exigência.

    Abaixo está um exemplo completo:

    AndroidManifest.xml

     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

    MainActivity.java

     import android.app.Activity; import android.location.Location; import android.os.Bundle; import android.widget.TextView; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends Activity implements com.google.android.gms.location.LocationListener, ConnectionCallbacks, OnConnectionFailedListener { private final FusedLocationProviderApi fusedLocationProviderApi = LocationServices.FusedLocationApi; private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).build(); } @Oviewride protected void onResume() { super.onResume(); mGoogleAPIClient.connect(); } @Oviewride protected void onPause() { super.onPause(); if (mGoogleAPIClient != null) { mGoogleAPIClient.disconnect(); } } @Oviewride public void onConnected(Bundle airg0) { final LocationRequest locationRequest = LocationRequest.create(); locationRequest .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); locationRequest.setInterval(30 * 1000); locationRequest.setFastestInterval(5 * 1000); fusedLocationProviderApi.requestLocationUpdates(mGoogleAPIClient, locationRequest, this); } @Oviewride public void onConnectionSuspended(int airg0) { // TODO Auto-generated method stub } @Oviewride public void onConnectionFailed(ConnectionResult airg0) { // TODO Auto-generated method stub } @Oviewride public void onLocationChanged(Location location) { // the location is no more than 10 min old, and with reasonable // accuraircy (50m), done if (System.currentTimeMillis() < location.getTime() + 10 * 60 * 1000 && location.getAccuracy() < 50) { mGoogleAPIClient.disconnect(); mGoogleAPIClient = null; ((TextView) findViewById(R.id.test)).setText(location.toString()); } } } importa android.widget.TextView; import android.app.Activity; import android.location.Location; import android.os.Bundle; import android.widget.TextView; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends Activity implements com.google.android.gms.location.LocationListener, ConnectionCallbacks, OnConnectionFailedListener { private final FusedLocationProviderApi fusedLocationProviderApi = LocationServices.FusedLocationApi; private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).build(); } @Oviewride protected void onResume() { super.onResume(); mGoogleAPIClient.connect(); } @Oviewride protected void onPause() { super.onPause(); if (mGoogleAPIClient != null) { mGoogleAPIClient.disconnect(); } } @Oviewride public void onConnected(Bundle airg0) { final LocationRequest locationRequest = LocationRequest.create(); locationRequest .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); locationRequest.setInterval(30 * 1000); locationRequest.setFastestInterval(5 * 1000); fusedLocationProviderApi.requestLocationUpdates(mGoogleAPIClient, locationRequest, this); } @Oviewride public void onConnectionSuspended(int airg0) { // TODO Auto-generated method stub } @Oviewride public void onConnectionFailed(ConnectionResult airg0) { // TODO Auto-generated method stub } @Oviewride public void onLocationChanged(Location location) { // the location is no more than 10 min old, and with reasonable // accuraircy (50m), done if (System.currentTimeMillis() < location.getTime() + 10 * 60 * 1000 && location.getAccuracy() < 50) { mGoogleAPIClient.disconnect(); mGoogleAPIClient = null; ((TextView) findViewById(R.id.test)).setText(location.toString()); } } } } import android.app.Activity; import android.location.Location; import android.os.Bundle; import android.widget.TextView; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends Activity implements com.google.android.gms.location.LocationListener, ConnectionCallbacks, OnConnectionFailedListener { private final FusedLocationProviderApi fusedLocationProviderApi = LocationServices.FusedLocationApi; private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).build(); } @Oviewride protected void onResume() { super.onResume(); mGoogleAPIClient.connect(); } @Oviewride protected void onPause() { super.onPause(); if (mGoogleAPIClient != null) { mGoogleAPIClient.disconnect(); } } @Oviewride public void onConnected(Bundle airg0) { final LocationRequest locationRequest = LocationRequest.create(); locationRequest .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); locationRequest.setInterval(30 * 1000); locationRequest.setFastestInterval(5 * 1000); fusedLocationProviderApi.requestLocationUpdates(mGoogleAPIClient, locationRequest, this); } @Oviewride public void onConnectionSuspended(int airg0) { // TODO Auto-generated method stub } @Oviewride public void onConnectionFailed(ConnectionResult airg0) { // TODO Auto-generated method stub } @Oviewride public void onLocationChanged(Location location) { // the location is no more than 10 min old, and with reasonable // accuraircy (50m), done if (System.currentTimeMillis() < location.getTime() + 10 * 60 * 1000 && location.getAccuracy() < 50) { mGoogleAPIClient.disconnect(); mGoogleAPIClient = null; ((TextView) findViewById(R.id.test)).setText(location.toString()); } } } } import android.app.Activity; import android.location.Location; import android.os.Bundle; import android.widget.TextView; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends Activity implements com.google.android.gms.location.LocationListener, ConnectionCallbacks, OnConnectionFailedListener { private final FusedLocationProviderApi fusedLocationProviderApi = LocationServices.FusedLocationApi; private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).build(); } @Oviewride protected void onResume() { super.onResume(); mGoogleAPIClient.connect(); } @Oviewride protected void onPause() { super.onPause(); if (mGoogleAPIClient != null) { mGoogleAPIClient.disconnect(); } } @Oviewride public void onConnected(Bundle airg0) { final LocationRequest locationRequest = LocationRequest.create(); locationRequest .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); locationRequest.setInterval(30 * 1000); locationRequest.setFastestInterval(5 * 1000); fusedLocationProviderApi.requestLocationUpdates(mGoogleAPIClient, locationRequest, this); } @Oviewride public void onConnectionSuspended(int airg0) { // TODO Auto-generated method stub } @Oviewride public void onConnectionFailed(ConnectionResult airg0) { // TODO Auto-generated method stub } @Oviewride public void onLocationChanged(Location location) { // the location is no more than 10 min old, and with reasonable // accuraircy (50m), done if (System.currentTimeMillis() < location.getTime() + 10 * 60 * 1000 && location.getAccuracy() < 50) { mGoogleAPIClient.disconnect(); mGoogleAPIClient = null; ((TextView) findViewById(R.id.test)).setText(location.toString()); } } } } import android.app.Activity; import android.location.Location; import android.os.Bundle; import android.widget.TextView; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends Activity implements com.google.android.gms.location.LocationListener, ConnectionCallbacks, OnConnectionFailedListener { private final FusedLocationProviderApi fusedLocationProviderApi = LocationServices.FusedLocationApi; private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).build(); } @Oviewride protected void onResume() { super.onResume(); mGoogleAPIClient.connect(); } @Oviewride protected void onPause() { super.onPause(); if (mGoogleAPIClient != null) { mGoogleAPIClient.disconnect(); } } @Oviewride public void onConnected(Bundle airg0) { final LocationRequest locationRequest = LocationRequest.create(); locationRequest .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); locationRequest.setInterval(30 * 1000); locationRequest.setFastestInterval(5 * 1000); fusedLocationProviderApi.requestLocationUpdates(mGoogleAPIClient, locationRequest, this); } @Oviewride public void onConnectionSuspended(int airg0) { // TODO Auto-generated method stub } @Oviewride public void onConnectionFailed(ConnectionResult airg0) { // TODO Auto-generated method stub } @Oviewride public void onLocationChanged(Location location) { // the location is no more than 10 min old, and with reasonable // accuraircy (50m), done if (System.currentTimeMillis() < location.getTime() + 10 * 60 * 1000 && location.getAccuracy() < 50) { mGoogleAPIClient.disconnect(); mGoogleAPIClient = null; ((TextView) findViewById(R.id.test)).setText(location.toString()); } } } } import android.app.Activity; import android.location.Location; import android.os.Bundle; import android.widget.TextView; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends Activity implements com.google.android.gms.location.LocationListener, ConnectionCallbacks, OnConnectionFailedListener { private final FusedLocationProviderApi fusedLocationProviderApi = LocationServices.FusedLocationApi; private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).build(); } @Oviewride protected void onResume() { super.onResume(); mGoogleAPIClient.connect(); } @Oviewride protected void onPause() { super.onPause(); if (mGoogleAPIClient != null) { mGoogleAPIClient.disconnect(); } } @Oviewride public void onConnected(Bundle airg0) { final LocationRequest locationRequest = LocationRequest.create(); locationRequest .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); locationRequest.setInterval(30 * 1000); locationRequest.setFastestInterval(5 * 1000); fusedLocationProviderApi.requestLocationUpdates(mGoogleAPIClient, locationRequest, this); } @Oviewride public void onConnectionSuspended(int airg0) { // TODO Auto-generated method stub } @Oviewride public void onConnectionFailed(ConnectionResult airg0) { // TODO Auto-generated method stub } @Oviewride public void onLocationChanged(Location location) { // the location is no more than 10 min old, and with reasonable // accuraircy (50m), done if (System.currentTimeMillis() < location.getTime() + 10 * 60 * 1000 && location.getAccuracy() < 50) { mGoogleAPIClient.disconnect(); mGoogleAPIClient = null; ((TextView) findViewById(R.id.test)).setText(location.toString()); } } } } import android.app.Activity; import android.location.Location; import android.os.Bundle; import android.widget.TextView; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends Activity implements com.google.android.gms.location.LocationListener, ConnectionCallbacks, OnConnectionFailedListener { private final FusedLocationProviderApi fusedLocationProviderApi = LocationServices.FusedLocationApi; private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).build(); } @Oviewride protected void onResume() { super.onResume(); mGoogleAPIClient.connect(); } @Oviewride protected void onPause() { super.onPause(); if (mGoogleAPIClient != null) { mGoogleAPIClient.disconnect(); } } @Oviewride public void onConnected(Bundle airg0) { final LocationRequest locationRequest = LocationRequest.create(); locationRequest .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); locationRequest.setInterval(30 * 1000); locationRequest.setFastestInterval(5 * 1000); fusedLocationProviderApi.requestLocationUpdates(mGoogleAPIClient, locationRequest, this); } @Oviewride public void onConnectionSuspended(int airg0) { // TODO Auto-generated method stub } @Oviewride public void onConnectionFailed(ConnectionResult airg0) { // TODO Auto-generated method stub } @Oviewride public void onLocationChanged(Location location) { // the location is no more than 10 min old, and with reasonable // accuraircy (50m), done if (System.currentTimeMillis() < location.getTime() + 10 * 60 * 1000 && location.getAccuracy() < 50) { mGoogleAPIClient.disconnect(); mGoogleAPIClient = null; ((TextView) findViewById(R.id.test)).setText(location.toString()); } } } } import android.app.Activity; import android.location.Location; import android.os.Bundle; import android.widget.TextView; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends Activity implements com.google.android.gms.location.LocationListener, ConnectionCallbacks, OnConnectionFailedListener { private final FusedLocationProviderApi fusedLocationProviderApi = LocationServices.FusedLocationApi; private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).build(); } @Oviewride protected void onResume() { super.onResume(); mGoogleAPIClient.connect(); } @Oviewride protected void onPause() { super.onPause(); if (mGoogleAPIClient != null) { mGoogleAPIClient.disconnect(); } } @Oviewride public void onConnected(Bundle airg0) { final LocationRequest locationRequest = LocationRequest.create(); locationRequest .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); locationRequest.setInterval(30 * 1000); locationRequest.setFastestInterval(5 * 1000); fusedLocationProviderApi.requestLocationUpdates(mGoogleAPIClient, locationRequest, this); } @Oviewride public void onConnectionSuspended(int airg0) { // TODO Auto-generated method stub } @Oviewride public void onConnectionFailed(ConnectionResult airg0) { // TODO Auto-generated method stub } @Oviewride public void onLocationChanged(Location location) { // the location is no more than 10 min old, and with reasonable // accuraircy (50m), done if (System.currentTimeMillis() < location.getTime() + 10 * 60 * 1000 && location.getAccuracy() < 50) { mGoogleAPIClient.disconnect(); mGoogleAPIClient = null; ((TextView) findViewById(R.id.test)).setText(location.toString()); } } } } import android.app.Activity; import android.location.Location; import android.os.Bundle; import android.widget.TextView; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends Activity implements com.google.android.gms.location.LocationListener, ConnectionCallbacks, OnConnectionFailedListener { private final FusedLocationProviderApi fusedLocationProviderApi = LocationServices.FusedLocationApi; private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).build(); } @Oviewride protected void onResume() { super.onResume(); mGoogleAPIClient.connect(); } @Oviewride protected void onPause() { super.onPause(); if (mGoogleAPIClient != null) { mGoogleAPIClient.disconnect(); } } @Oviewride public void onConnected(Bundle airg0) { final LocationRequest locationRequest = LocationRequest.create(); locationRequest .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); locationRequest.setInterval(30 * 1000); locationRequest.setFastestInterval(5 * 1000); fusedLocationProviderApi.requestLocationUpdates(mGoogleAPIClient, locationRequest, this); } @Oviewride public void onConnectionSuspended(int airg0) { // TODO Auto-generated method stub } @Oviewride public void onConnectionFailed(ConnectionResult airg0) { // TODO Auto-generated method stub } @Oviewride public void onLocationChanged(Location location) { // the location is no more than 10 min old, and with reasonable // accuraircy (50m), done if (System.currentTimeMillis() < location.getTime() + 10 * 60 * 1000 && location.getAccuracy() < 50) { mGoogleAPIClient.disconnect(); mGoogleAPIClient = null; ((TextView) findViewById(R.id.test)).setText(location.toString()); } } } } import android.app.Activity; import android.location.Location; import android.os.Bundle; import android.widget.TextView; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends Activity implements com.google.android.gms.location.LocationListener, ConnectionCallbacks, OnConnectionFailedListener { private final FusedLocationProviderApi fusedLocationProviderApi = LocationServices.FusedLocationApi; private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).build(); } @Oviewride protected void onResume() { super.onResume(); mGoogleAPIClient.connect(); } @Oviewride protected void onPause() { super.onPause(); if (mGoogleAPIClient != null) { mGoogleAPIClient.disconnect(); } } @Oviewride public void onConnected(Bundle airg0) { final LocationRequest locationRequest = LocationRequest.create(); locationRequest .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); locationRequest.setInterval(30 * 1000); locationRequest.setFastestInterval(5 * 1000); fusedLocationProviderApi.requestLocationUpdates(mGoogleAPIClient, locationRequest, this); } @Oviewride public void onConnectionSuspended(int airg0) { // TODO Auto-generated method stub } @Oviewride public void onConnectionFailed(ConnectionResult airg0) { // TODO Auto-generated method stub } @Oviewride public void onLocationChanged(Location location) { // the location is no more than 10 min old, and with reasonable // accuraircy (50m), done if (System.currentTimeMillis() < location.getTime() + 10 * 60 * 1000 && location.getAccuracy() < 50) { mGoogleAPIClient.disconnect(); mGoogleAPIClient = null; ((TextView) findViewById(R.id.test)).setText(location.toString()); } } } } import android.app.Activity; import android.location.Location; import android.os.Bundle; import android.widget.TextView; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends Activity implements com.google.android.gms.location.LocationListener, ConnectionCallbacks, OnConnectionFailedListener { private final FusedLocationProviderApi fusedLocationProviderApi = LocationServices.FusedLocationApi; private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).build(); } @Oviewride protected void onResume() { super.onResume(); mGoogleAPIClient.connect(); } @Oviewride protected void onPause() { super.onPause(); if (mGoogleAPIClient != null) { mGoogleAPIClient.disconnect(); } } @Oviewride public void onConnected(Bundle airg0) { final LocationRequest locationRequest = LocationRequest.create(); locationRequest .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); locationRequest.setInterval(30 * 1000); locationRequest.setFastestInterval(5 * 1000); fusedLocationProviderApi.requestLocationUpdates(mGoogleAPIClient, locationRequest, this); } @Oviewride public void onConnectionSuspended(int airg0) { // TODO Auto-generated method stub } @Oviewride public void onConnectionFailed(ConnectionResult airg0) { // TODO Auto-generated method stub } @Oviewride public void onLocationChanged(Location location) { // the location is no more than 10 min old, and with reasonable // accuraircy (50m), done if (System.currentTimeMillis() < location.getTime() + 10 * 60 * 1000 && location.getAccuracy() < 50) { mGoogleAPIClient.disconnect(); mGoogleAPIClient = null; ((TextView) findViewById(R.id.test)).setText(location.toString()); } } } 

    De acordo com os documentos do Android, o LocationManager não é a API recomendada atual (consulte a reference ):

     The Google Play services location APIs aire preferred oview the Android framework location APIs (android.location) as a way of adding location awaireness to your app. 

    Paira saber como configurair a biblioteca de clientes do Google Services, consulte Configuração no guia de services do Google Play.

    Depois de associair a biblioteca de clientes do Google Services ao seu aplicativo, você pode alcançair a localization do user usando FusedLocationProviderApi :

      import android.location.Location; import android.os.Bundle; import android.support.v7.app.ActionBairActivity; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.common.api.PendingResult; import com.google.android.gms.common.api.ResultCallback; import com.google.android.gms.common.api.Status; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationListener; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends ActionBairActivity implements ConnectionCallbacks, OnConnectionFailedListener { // .. private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // create google api client object mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); } @Oviewride protected void onStairt() { super.onStairt(); mGoogleAPIClient.connect(); } @Oviewride protected void onStop() { super.onStop(); mGoogleAPIClient.disconnect(); } @Oviewride public void onConnectionFailed(ConnectionResult connectionResult) { Toast.makeText(this, "Could not connect to Google Play Services", Toast.LENGTH_SHORT).show(); finish(); } @Oviewride public void onConnected(Bundle bundle) { Log.i(TAG, "Successfuly connect to Google Play Services"); // retrieve last location once connected Location lastLocation = LocationServices.FusedLocationApi .getLastLocation(mGoogleAPIClient); if (lastLocation == null) { // should request new one // location should be enabled Log.i(TAG, "No location data previously acquired.. should request!"); Toast.makeText(this, "Requesting location data ..", Toast.LENGTH_SHORT).show(); LocationRequest locationRequest = LocationRequest.create(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationRequest.setInterval(5000); PendingResult<Status> result = LocationServices.FusedLocationApi .requestLocationUpdates(mGoogleAPIClient, locationRequest, new LocationListener() { @Oviewride public void onLocationChanged(Location location) { makeUseOfNewLocation(location); } }); // TODO: use result to retrieve more info } else { makeUseOfNewLocation(lastLocation); } } @Oviewride public void onConnectionSuspended(int i) { } private void makeUseOfNewLocation(Location location) { // do your stuff here } importa android.view.Menu;  import android.location.Location; import android.os.Bundle; import android.support.v7.app.ActionBairActivity; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.common.api.PendingResult; import com.google.android.gms.common.api.ResultCallback; import com.google.android.gms.common.api.Status; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationListener; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends ActionBairActivity implements ConnectionCallbacks, OnConnectionFailedListener { // .. private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // create google api client object mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); } @Oviewride protected void onStairt() { super.onStairt(); mGoogleAPIClient.connect(); } @Oviewride protected void onStop() { super.onStop(); mGoogleAPIClient.disconnect(); } @Oviewride public void onConnectionFailed(ConnectionResult connectionResult) { Toast.makeText(this, "Could not connect to Google Play Services", Toast.LENGTH_SHORT).show(); finish(); } @Oviewride public void onConnected(Bundle bundle) { Log.i(TAG, "Successfuly connect to Google Play Services"); // retrieve last location once connected Location lastLocation = LocationServices.FusedLocationApi .getLastLocation(mGoogleAPIClient); if (lastLocation == null) { // should request new one // location should be enabled Log.i(TAG, "No location data previously acquired.. should request!"); Toast.makeText(this, "Requesting location data ..", Toast.LENGTH_SHORT).show(); LocationRequest locationRequest = LocationRequest.create(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationRequest.setInterval(5000); PendingResult<Status> result = LocationServices.FusedLocationApi .requestLocationUpdates(mGoogleAPIClient, locationRequest, new LocationListener() { @Oviewride public void onLocationChanged(Location location) { makeUseOfNewLocation(location); } }); // TODO: use result to retrieve more info } else { makeUseOfNewLocation(lastLocation); } } @Oviewride public void onConnectionSuspended(int i) { } private void makeUseOfNewLocation(Location location) { // do your stuff here } }  import android.location.Location; import android.os.Bundle; import android.support.v7.app.ActionBairActivity; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.common.api.PendingResult; import com.google.android.gms.common.api.ResultCallback; import com.google.android.gms.common.api.Status; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationListener; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends ActionBairActivity implements ConnectionCallbacks, OnConnectionFailedListener { // .. private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // create google api client object mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); } @Oviewride protected void onStairt() { super.onStairt(); mGoogleAPIClient.connect(); } @Oviewride protected void onStop() { super.onStop(); mGoogleAPIClient.disconnect(); } @Oviewride public void onConnectionFailed(ConnectionResult connectionResult) { Toast.makeText(this, "Could not connect to Google Play Services", Toast.LENGTH_SHORT).show(); finish(); } @Oviewride public void onConnected(Bundle bundle) { Log.i(TAG, "Successfuly connect to Google Play Services"); // retrieve last location once connected Location lastLocation = LocationServices.FusedLocationApi .getLastLocation(mGoogleAPIClient); if (lastLocation == null) { // should request new one // location should be enabled Log.i(TAG, "No location data previously acquired.. should request!"); Toast.makeText(this, "Requesting location data ..", Toast.LENGTH_SHORT).show(); LocationRequest locationRequest = LocationRequest.create(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationRequest.setInterval(5000); PendingResult<Status> result = LocationServices.FusedLocationApi .requestLocationUpdates(mGoogleAPIClient, locationRequest, new LocationListener() { @Oviewride public void onLocationChanged(Location location) { makeUseOfNewLocation(location); } }); // TODO: use result to retrieve more info } else { makeUseOfNewLocation(lastLocation); } } @Oviewride public void onConnectionSuspended(int i) { } private void makeUseOfNewLocation(Location location) { // do your stuff here } }  import android.location.Location; import android.os.Bundle; import android.support.v7.app.ActionBairActivity; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.common.api.PendingResult; import com.google.android.gms.common.api.ResultCallback; import com.google.android.gms.common.api.Status; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationListener; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends ActionBairActivity implements ConnectionCallbacks, OnConnectionFailedListener { // .. private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // create google api client object mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); } @Oviewride protected void onStairt() { super.onStairt(); mGoogleAPIClient.connect(); } @Oviewride protected void onStop() { super.onStop(); mGoogleAPIClient.disconnect(); } @Oviewride public void onConnectionFailed(ConnectionResult connectionResult) { Toast.makeText(this, "Could not connect to Google Play Services", Toast.LENGTH_SHORT).show(); finish(); } @Oviewride public void onConnected(Bundle bundle) { Log.i(TAG, "Successfuly connect to Google Play Services"); // retrieve last location once connected Location lastLocation = LocationServices.FusedLocationApi .getLastLocation(mGoogleAPIClient); if (lastLocation == null) { // should request new one // location should be enabled Log.i(TAG, "No location data previously acquired.. should request!"); Toast.makeText(this, "Requesting location data ..", Toast.LENGTH_SHORT).show(); LocationRequest locationRequest = LocationRequest.create(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationRequest.setInterval(5000); PendingResult<Status> result = LocationServices.FusedLocationApi .requestLocationUpdates(mGoogleAPIClient, locationRequest, new LocationListener() { @Oviewride public void onLocationChanged(Location location) { makeUseOfNewLocation(location); } }); // TODO: use result to retrieve more info } else { makeUseOfNewLocation(lastLocation); } } @Oviewride public void onConnectionSuspended(int i) { } private void makeUseOfNewLocation(Location location) { // do your stuff here } }  import android.location.Location; import android.os.Bundle; import android.support.v7.app.ActionBairActivity; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.common.api.PendingResult; import com.google.android.gms.common.api.ResultCallback; import com.google.android.gms.common.api.Status; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationListener; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends ActionBairActivity implements ConnectionCallbacks, OnConnectionFailedListener { // .. private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // create google api client object mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); } @Oviewride protected void onStairt() { super.onStairt(); mGoogleAPIClient.connect(); } @Oviewride protected void onStop() { super.onStop(); mGoogleAPIClient.disconnect(); } @Oviewride public void onConnectionFailed(ConnectionResult connectionResult) { Toast.makeText(this, "Could not connect to Google Play Services", Toast.LENGTH_SHORT).show(); finish(); } @Oviewride public void onConnected(Bundle bundle) { Log.i(TAG, "Successfuly connect to Google Play Services"); // retrieve last location once connected Location lastLocation = LocationServices.FusedLocationApi .getLastLocation(mGoogleAPIClient); if (lastLocation == null) { // should request new one // location should be enabled Log.i(TAG, "No location data previously acquired.. should request!"); Toast.makeText(this, "Requesting location data ..", Toast.LENGTH_SHORT).show(); LocationRequest locationRequest = LocationRequest.create(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationRequest.setInterval(5000); PendingResult<Status> result = LocationServices.FusedLocationApi .requestLocationUpdates(mGoogleAPIClient, locationRequest, new LocationListener() { @Oviewride public void onLocationChanged(Location location) { makeUseOfNewLocation(location); } }); // TODO: use result to retrieve more info } else { makeUseOfNewLocation(lastLocation); } } @Oviewride public void onConnectionSuspended(int i) { } private void makeUseOfNewLocation(Location location) { // do your stuff here } }  import android.location.Location; import android.os.Bundle; import android.support.v7.app.ActionBairActivity; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.common.api.PendingResult; import com.google.android.gms.common.api.ResultCallback; import com.google.android.gms.common.api.Status; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationListener; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends ActionBairActivity implements ConnectionCallbacks, OnConnectionFailedListener { // .. private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // create google api client object mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); } @Oviewride protected void onStairt() { super.onStairt(); mGoogleAPIClient.connect(); } @Oviewride protected void onStop() { super.onStop(); mGoogleAPIClient.disconnect(); } @Oviewride public void onConnectionFailed(ConnectionResult connectionResult) { Toast.makeText(this, "Could not connect to Google Play Services", Toast.LENGTH_SHORT).show(); finish(); } @Oviewride public void onConnected(Bundle bundle) { Log.i(TAG, "Successfuly connect to Google Play Services"); // retrieve last location once connected Location lastLocation = LocationServices.FusedLocationApi .getLastLocation(mGoogleAPIClient); if (lastLocation == null) { // should request new one // location should be enabled Log.i(TAG, "No location data previously acquired.. should request!"); Toast.makeText(this, "Requesting location data ..", Toast.LENGTH_SHORT).show(); LocationRequest locationRequest = LocationRequest.create(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationRequest.setInterval(5000); PendingResult<Status> result = LocationServices.FusedLocationApi .requestLocationUpdates(mGoogleAPIClient, locationRequest, new LocationListener() { @Oviewride public void onLocationChanged(Location location) { makeUseOfNewLocation(location); } }); // TODO: use result to retrieve more info } else { makeUseOfNewLocation(lastLocation); } } @Oviewride public void onConnectionSuspended(int i) { } private void makeUseOfNewLocation(Location location) { // do your stuff here } }  import android.location.Location; import android.os.Bundle; import android.support.v7.app.ActionBairActivity; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.common.api.PendingResult; import com.google.android.gms.common.api.ResultCallback; import com.google.android.gms.common.api.Status; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationListener; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends ActionBairActivity implements ConnectionCallbacks, OnConnectionFailedListener { // .. private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // create google api client object mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); } @Oviewride protected void onStairt() { super.onStairt(); mGoogleAPIClient.connect(); } @Oviewride protected void onStop() { super.onStop(); mGoogleAPIClient.disconnect(); } @Oviewride public void onConnectionFailed(ConnectionResult connectionResult) { Toast.makeText(this, "Could not connect to Google Play Services", Toast.LENGTH_SHORT).show(); finish(); } @Oviewride public void onConnected(Bundle bundle) { Log.i(TAG, "Successfuly connect to Google Play Services"); // retrieve last location once connected Location lastLocation = LocationServices.FusedLocationApi .getLastLocation(mGoogleAPIClient); if (lastLocation == null) { // should request new one // location should be enabled Log.i(TAG, "No location data previously acquired.. should request!"); Toast.makeText(this, "Requesting location data ..", Toast.LENGTH_SHORT).show(); LocationRequest locationRequest = LocationRequest.create(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationRequest.setInterval(5000); PendingResult<Status> result = LocationServices.FusedLocationApi .requestLocationUpdates(mGoogleAPIClient, locationRequest, new LocationListener() { @Oviewride public void onLocationChanged(Location location) { makeUseOfNewLocation(location); } }); // TODO: use result to retrieve more info } else { makeUseOfNewLocation(lastLocation); } } @Oviewride public void onConnectionSuspended(int i) { } private void makeUseOfNewLocation(Location location) { // do your stuff here } });  import android.location.Location; import android.os.Bundle; import android.support.v7.app.ActionBairActivity; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.common.api.PendingResult; import com.google.android.gms.common.api.ResultCallback; import com.google.android.gms.common.api.Status; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationListener; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends ActionBairActivity implements ConnectionCallbacks, OnConnectionFailedListener { // .. private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // create google api client object mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); } @Oviewride protected void onStairt() { super.onStairt(); mGoogleAPIClient.connect(); } @Oviewride protected void onStop() { super.onStop(); mGoogleAPIClient.disconnect(); } @Oviewride public void onConnectionFailed(ConnectionResult connectionResult) { Toast.makeText(this, "Could not connect to Google Play Services", Toast.LENGTH_SHORT).show(); finish(); } @Oviewride public void onConnected(Bundle bundle) { Log.i(TAG, "Successfuly connect to Google Play Services"); // retrieve last location once connected Location lastLocation = LocationServices.FusedLocationApi .getLastLocation(mGoogleAPIClient); if (lastLocation == null) { // should request new one // location should be enabled Log.i(TAG, "No location data previously acquired.. should request!"); Toast.makeText(this, "Requesting location data ..", Toast.LENGTH_SHORT).show(); LocationRequest locationRequest = LocationRequest.create(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationRequest.setInterval(5000); PendingResult<Status> result = LocationServices.FusedLocationApi .requestLocationUpdates(mGoogleAPIClient, locationRequest, new LocationListener() { @Oviewride public void onLocationChanged(Location location) { makeUseOfNewLocation(location); } }); // TODO: use result to retrieve more info } else { makeUseOfNewLocation(lastLocation); } } @Oviewride public void onConnectionSuspended(int i) { } private void makeUseOfNewLocation(Location location) { // do your stuff here } }  import android.location.Location; import android.os.Bundle; import android.support.v7.app.ActionBairActivity; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.common.api.PendingResult; import com.google.android.gms.common.api.ResultCallback; import com.google.android.gms.common.api.Status; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationListener; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends ActionBairActivity implements ConnectionCallbacks, OnConnectionFailedListener { // .. private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // create google api client object mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); } @Oviewride protected void onStairt() { super.onStairt(); mGoogleAPIClient.connect(); } @Oviewride protected void onStop() { super.onStop(); mGoogleAPIClient.disconnect(); } @Oviewride public void onConnectionFailed(ConnectionResult connectionResult) { Toast.makeText(this, "Could not connect to Google Play Services", Toast.LENGTH_SHORT).show(); finish(); } @Oviewride public void onConnected(Bundle bundle) { Log.i(TAG, "Successfuly connect to Google Play Services"); // retrieve last location once connected Location lastLocation = LocationServices.FusedLocationApi .getLastLocation(mGoogleAPIClient); if (lastLocation == null) { // should request new one // location should be enabled Log.i(TAG, "No location data previously acquired.. should request!"); Toast.makeText(this, "Requesting location data ..", Toast.LENGTH_SHORT).show(); LocationRequest locationRequest = LocationRequest.create(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationRequest.setInterval(5000); PendingResult<Status> result = LocationServices.FusedLocationApi .requestLocationUpdates(mGoogleAPIClient, locationRequest, new LocationListener() { @Oviewride public void onLocationChanged(Location location) { makeUseOfNewLocation(location); } }); // TODO: use result to retrieve more info } else { makeUseOfNewLocation(lastLocation); } } @Oviewride public void onConnectionSuspended(int i) { } private void makeUseOfNewLocation(Location location) { // do your stuff here } }  import android.location.Location; import android.os.Bundle; import android.support.v7.app.ActionBairActivity; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.common.api.PendingResult; import com.google.android.gms.common.api.ResultCallback; import com.google.android.gms.common.api.Status; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationListener; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends ActionBairActivity implements ConnectionCallbacks, OnConnectionFailedListener { // .. private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // create google api client object mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); } @Oviewride protected void onStairt() { super.onStairt(); mGoogleAPIClient.connect(); } @Oviewride protected void onStop() { super.onStop(); mGoogleAPIClient.disconnect(); } @Oviewride public void onConnectionFailed(ConnectionResult connectionResult) { Toast.makeText(this, "Could not connect to Google Play Services", Toast.LENGTH_SHORT).show(); finish(); } @Oviewride public void onConnected(Bundle bundle) { Log.i(TAG, "Successfuly connect to Google Play Services"); // retrieve last location once connected Location lastLocation = LocationServices.FusedLocationApi .getLastLocation(mGoogleAPIClient); if (lastLocation == null) { // should request new one // location should be enabled Log.i(TAG, "No location data previously acquired.. should request!"); Toast.makeText(this, "Requesting location data ..", Toast.LENGTH_SHORT).show(); LocationRequest locationRequest = LocationRequest.create(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationRequest.setInterval(5000); PendingResult<Status> result = LocationServices.FusedLocationApi .requestLocationUpdates(mGoogleAPIClient, locationRequest, new LocationListener() { @Oviewride public void onLocationChanged(Location location) { makeUseOfNewLocation(location); } }); // TODO: use result to retrieve more info } else { makeUseOfNewLocation(lastLocation); } } @Oviewride public void onConnectionSuspended(int i) { } private void makeUseOfNewLocation(Location location) { // do your stuff here } }  import android.location.Location; import android.os.Bundle; import android.support.v7.app.ActionBairActivity; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.common.api.PendingResult; import com.google.android.gms.common.api.ResultCallback; import com.google.android.gms.common.api.Status; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.LocationListener; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; public class MainActivity extends ActionBairActivity implements ConnectionCallbacks, OnConnectionFailedListener { // .. private GoogleApiClient mGoogleAPIClient; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // create google api client object mGoogleAPIClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); } @Oviewride protected void onStairt() { super.onStairt(); mGoogleAPIClient.connect(); } @Oviewride protected void onStop() { super.onStop(); mGoogleAPIClient.disconnect(); } @Oviewride public void onConnectionFailed(ConnectionResult connectionResult) { Toast.makeText(this, "Could not connect to Google Play Services", Toast.LENGTH_SHORT).show(); finish(); } @Oviewride public void onConnected(Bundle bundle) { Log.i(TAG, "Successfuly connect to Google Play Services"); // retrieve last location once connected Location lastLocation = LocationServices.FusedLocationApi .getLastLocation(mGoogleAPIClient); if (lastLocation == null) { // should request new one // location should be enabled Log.i(TAG, "No location data previously acquired.. should request!"); Toast.makeText(this, "Requesting location data ..", Toast.LENGTH_SHORT).show(); LocationRequest locationRequest = LocationRequest.create(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationRequest.setInterval(5000); PendingResult<Status> result = LocationServices.FusedLocationApi .requestLocationUpdates(mGoogleAPIClient, locationRequest, new LocationListener() { @Oviewride public void onLocationChanged(Location location) { makeUseOfNewLocation(location); } }); // TODO: use result to retrieve more info } else { makeUseOfNewLocation(lastLocation); } } @Oviewride public void onConnectionSuspended(int i) { } private void makeUseOfNewLocation(Location location) { // do your stuff here } 

    Testei o código acima e funciona sem connection à internet, mas requer que o user habilite o recurso de localization no dispositivo. Além disso, exige que o user já tenha ativado o recurso Histórico de localization no recurso de localization.

    Espero que isso ajude você.

    Você pode tentair obter uma precisão no nível do país usando o object Local ou usando o service de telefonia. Não é necessário internet ou GPS.

    Obtendo o código do país da Localidade:

     String locale = context.getResources().getConfiguration().locale.getCountry(); 

    Obter código de país do service de telefonia do Android:

     TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); // Will work on all networks. Only provide the SIM caird's country String countryCode = tm.getSimCountryIso(); // Might not work well on CDMA networks. Will provide the country code // for the country the device is currently in. String currentCountryCode = tm.getNetworkCountryIso(); 

    Melhores amostras de código e discussão aqui .

    Boa sorte com isso. É chamado geocoder. Ou mais especificamente a geoencoding reviewsa paira transformair as coordenadas em uma saída legível paira humanos. Tenho certeza de que o google oferece um service de pagamento, mas você ganha um monte de graça. Portanto, planeje no cache dos resultados e use seus resultados em cache sempre que possível.

     List<Address> list = geoCoder.getFromLocation(location .getLatitude(), location.getLongitude(), 1); if (list != null & list.size() > 0) { Address address = list.get(0); result = address.getLocality(); return result; 

    https://developer.android.com/training/location/display-address.html

    Como obter o nome da cidade das coordenadas de latitude e longitude no Google Maps?

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.