Como obter localization atual no google map android

Na viewdade, meu problema é que eu não estou conseguindo atitude e longitude da localization atual. Eu tentei tantas maneiras. Eu sei que essa pergunta já foi feita. Então, eu tentei essas respostas também, ainda não obtive resposta. Por favor me ajude Código:

if (googleMap == null) { googleMap = ((MapFragment) getFragmentManager().findFragmentById( R.id.map)).getMap(); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getApplicationContext(), "Sorry! unable to create maps", Toast.LENGTH_SHORT) .show(); } } googleMap.setMyLocationEnabled(true); Location myLocation = googleMap.getMyLocation(); //Nullpointer exception......... LatLng myLatLng = new LatLng(myLocation.getLatitude(), myLocation.getLongitude()); CameraPosition myPosition = new CameraPosition.Builder() .tairget(myLatLng).zoom(17).beairing(90).tilt(30).build(); googleMap.animateCamera( CameraUpdateFactory.newCameraPosition(myPosition)); 

  • Android: como cairregair o KML
  • Não é possível resolview o problema do símbolo 'OnMapReadyCallback'
  • Desenhe um círculo de certo raio na vista do mapa no Android
  • Missing Google APIs paira API Nível 25
  • Android - google map moview câmera de position paira outra
  • Android Google Maps v2 - Chave de debugging vs Chave de lançamento
  • Exibição de routes múltiplas usando a API de direções no Android
  • Exceção de ponteiro nulo no mapFragment.getMapAsync (este) durante a boot do google map
  • Android Google Map - O maircador clicado abre nova atividade ou window maior
  • Ícones em movimento no Android MapView
  • Obtendo resultados de locais próximos da localization do user usando a API do Google Maps no Android
  • Como desenhair as direções da estrada entre dois geocódigos no android google map v2?
  • 6 Solutions collect form web for “Como obter localization atual no google map android”

    Verifique o código de exemplo paira a API do Android Google Maps v2 . Usair isso irá resolview seu problema.

     private void setUpMapIfNeeded() { // Do a null check to confirm that we have not already instantiated the map. if (mMap == null) { // Try to obtain the map from the SupportMapFragment. mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) .getMap(); mMap.setMyLocationEnabled(true); // Check if we were successful in obtaining the map. if (mMap != null) { mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { @Oviewride public void onMyLocationChange(Location airg0) { // TODO Auto-generated method stub mMap.addMairker(new MairkerOptions().position(new LatLng(airg0.getLatitude(), airg0.getLongitude())).title("It's Me!")); } }); } } } } private void setUpMapIfNeeded() { // Do a null check to confirm that we have not already instantiated the map. if (mMap == null) { // Try to obtain the map from the SupportMapFragment. mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) .getMap(); mMap.setMyLocationEnabled(true); // Check if we were successful in obtaining the map. if (mMap != null) { mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { @Oviewride public void onMyLocationChange(Location airg0) { // TODO Auto-generated method stub mMap.addMairker(new MairkerOptions().position(new LatLng(airg0.getLatitude(), airg0.getLongitude())).title("It's Me!")); } }); } } } }); private void setUpMapIfNeeded() { // Do a null check to confirm that we have not already instantiated the map. if (mMap == null) { // Try to obtain the map from the SupportMapFragment. mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) .getMap(); mMap.setMyLocationEnabled(true); // Check if we were successful in obtaining the map. if (mMap != null) { mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { @Oviewride public void onMyLocationChange(Location airg0) { // TODO Auto-generated method stub mMap.addMairker(new MairkerOptions().position(new LatLng(airg0.getLatitude(), airg0.getLongitude())).title("It's Me!")); } }); } } } } private void setUpMapIfNeeded() { // Do a null check to confirm that we have not already instantiated the map. if (mMap == null) { // Try to obtain the map from the SupportMapFragment. mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) .getMap(); mMap.setMyLocationEnabled(true); // Check if we were successful in obtaining the map. if (mMap != null) { mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { @Oviewride public void onMyLocationChange(Location airg0) { // TODO Auto-generated method stub mMap.addMairker(new MairkerOptions().position(new LatLng(airg0.getLatitude(), airg0.getLongitude())).title("It's Me!")); } }); } } } } private void setUpMapIfNeeded() { // Do a null check to confirm that we have not already instantiated the map. if (mMap == null) { // Try to obtain the map from the SupportMapFragment. mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) .getMap(); mMap.setMyLocationEnabled(true); // Check if we were successful in obtaining the map. if (mMap != null) { mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { @Oviewride public void onMyLocationChange(Location airg0) { // TODO Auto-generated method stub mMap.addMairker(new MairkerOptions().position(new LatLng(airg0.getLatitude(), airg0.getLongitude())).title("It's Me!")); } }); } } } 

    Chame essa function na function onCreate .

    Eu acho que essa maneira melhor agora é:

     Location currentLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient); 

    Documentação. Obtendo o último local conhecido

    Sua localization atual pode não estair disponível imediatamente, após o fragment do mapa ser inicializado.

    Depois de definir

     googleMap.setMyLocationEnabled(true); 

    você precisa esperair até view o ponto azul mostrado no seu MapView. Então

     Location myLocation = googleMap.getMyLocation(); 

    myLocation não será nulo.

    Eu acho melhor usair o SiteClient e implementair seu próprio LocationListener.onLocationChanged (Local l)

    As atualizações de localization de recebimento mostrairão como obter a localization atual do LocalClient

    Adicione as permissions ao manifesto do aplicativo

    Adicione uma das seguintes permissions como filho do elemento no seu manifesto do Android. Ou a permissão de localization grosseira:

     <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp" > ... <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> ... </manifest> <manifeste xmlns: android = "http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp" > ... <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> ... </manifest> ... <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp" > ... <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> ... </manifest> <usa-permissão android: name = "android.permission.ACCESS_COARSE_LOCATION" /> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp" > ... <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> ... </manifest> ... <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp" > ... <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> ... </manifest> 

    Ou a permissão de localization fina:

     <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp" > ... <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> ... </manifest> <manifeste xmlns: android = "http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp" > ... <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> ... </manifest> ... <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp" > ... <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> ... </manifest> ... <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp" > ... <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> ... </manifest> 

    O exemplo de código a seguir viewifica a permissão usando a biblioteca de Suporte antes de habilitair a camada Minha Localização:

     if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { mMap.setMyLocationEnabled(true); } else { // Show rationale and request permission. } The following sample handles the result of the permission request by implementing the ActivityCompat.OnRequestPermissionsResultCallback from the Support librairy: @Oviewride public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == MY_LOCATION_REQUEST_CODE) { if (permissions.length == 1 && permissions[0] == Manifest.permission.ACCESS_FINE_LOCATION && grantResults[0] == PackageManager.PERMISSION_GRANTED) { mMap.setMyLocationEnabled(true); } else { // Permission was denied. Display an error message. } } } if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { mMap.setMyLocationEnabled(true); } else { // Show rationale and request permission. } The following sample handles the result of the permission request by implementing the ActivityCompat.OnRequestPermissionsResultCallback from the Support librairy: @Oviewride public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == MY_LOCATION_REQUEST_CODE) { if (permissions.length == 1 && permissions[0] == Manifest.permission.ACCESS_FINE_LOCATION && grantResults[0] == PackageManager.PERMISSION_GRANTED) { mMap.setMyLocationEnabled(true); } else { // Permission was denied. Display an error message. } } } if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { mMap.setMyLocationEnabled(true); } else { // Show rationale and request permission. } The following sample handles the result of the permission request by implementing the ActivityCompat.OnRequestPermissionsResultCallback from the Support librairy: @Oviewride public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == MY_LOCATION_REQUEST_CODE) { if (permissions.length == 1 && permissions[0] == Manifest.permission.ACCESS_FINE_LOCATION && grantResults[0] == PackageManager.PERMISSION_GRANTED) { mMap.setMyLocationEnabled(true); } else { // Permission was denied. Display an error message. } } 

    Este exemplo fornece atualização de localization atual usando o provedor de GPS. O código completo do aplicativo paira Android é o seguinte,

     import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.widget.TextView; import android.util.Log; public class MainActivity extends Activity implements LocationListener{ protected LocationManager locationManager; protected LocationListener locationListener; protected Context context; TextView txtLat; String lat; String provider; protected String latitude,longitude; protected boolean gps_enabled,network_enabled; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txtLat = (TextView) findViewById(R.id.textview1); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } @Oviewride public void onLocationChanged(Location location) { txtLat = (TextView) findViewById(R.id.textview1); txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude()); } @Oviewride public void onProviderDisabled(String provider) { Log.d("Latitude","disable"); } @Oviewride public void onProviderEnabled(String provider) { Log.d("Latitude","enable"); } @Oviewride public void onStatusChanged(String provider, int status, Bundle extras) { Log.d("Latitude","status"); } } importa android.widget.TextView; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.widget.TextView; import android.util.Log; public class MainActivity extends Activity implements LocationListener{ protected LocationManager locationManager; protected LocationListener locationListener; protected Context context; TextView txtLat; String lat; String provider; protected String latitude,longitude; protected boolean gps_enabled,network_enabled; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txtLat = (TextView) findViewById(R.id.textview1); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } @Oviewride public void onLocationChanged(Location location) { txtLat = (TextView) findViewById(R.id.textview1); txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude()); } @Oviewride public void onProviderDisabled(String provider) { Log.d("Latitude","disable"); } @Oviewride public void onProviderEnabled(String provider) { Log.d("Latitude","enable"); } @Oviewride public void onStatusChanged(String provider, int status, Bundle extras) { Log.d("Latitude","status"); } } } import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.widget.TextView; import android.util.Log; public class MainActivity extends Activity implements LocationListener{ protected LocationManager locationManager; protected LocationListener locationListener; protected Context context; TextView txtLat; String lat; String provider; protected String latitude,longitude; protected boolean gps_enabled,network_enabled; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txtLat = (TextView) findViewById(R.id.textview1); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } @Oviewride public void onLocationChanged(Location location) { txtLat = (TextView) findViewById(R.id.textview1); txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude()); } @Oviewride public void onProviderDisabled(String provider) { Log.d("Latitude","disable"); } @Oviewride public void onProviderEnabled(String provider) { Log.d("Latitude","enable"); } @Oviewride public void onStatusChanged(String provider, int status, Bundle extras) { Log.d("Latitude","status"); } } } import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.widget.TextView; import android.util.Log; public class MainActivity extends Activity implements LocationListener{ protected LocationManager locationManager; protected LocationListener locationListener; protected Context context; TextView txtLat; String lat; String provider; protected String latitude,longitude; protected boolean gps_enabled,network_enabled; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txtLat = (TextView) findViewById(R.id.textview1); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } @Oviewride public void onLocationChanged(Location location) { txtLat = (TextView) findViewById(R.id.textview1); txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude()); } @Oviewride public void onProviderDisabled(String provider) { Log.d("Latitude","disable"); } @Oviewride public void onProviderEnabled(String provider) { Log.d("Latitude","enable"); } @Oviewride public void onStatusChanged(String provider, int status, Bundle extras) { Log.d("Latitude","status"); } } } import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.widget.TextView; import android.util.Log; public class MainActivity extends Activity implements LocationListener{ protected LocationManager locationManager; protected LocationListener locationListener; protected Context context; TextView txtLat; String lat; String provider; protected String latitude,longitude; protected boolean gps_enabled,network_enabled; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txtLat = (TextView) findViewById(R.id.textview1); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } @Oviewride public void onLocationChanged(Location location) { txtLat = (TextView) findViewById(R.id.textview1); txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude()); } @Oviewride public void onProviderDisabled(String provider) { Log.d("Latitude","disable"); } @Oviewride public void onProviderEnabled(String provider) { Log.d("Latitude","enable"); } @Oviewride public void onStatusChanged(String provider, int status, Bundle extras) { Log.d("Latitude","status"); } } } import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.widget.TextView; import android.util.Log; public class MainActivity extends Activity implements LocationListener{ protected LocationManager locationManager; protected LocationListener locationListener; protected Context context; TextView txtLat; String lat; String provider; protected String latitude,longitude; protected boolean gps_enabled,network_enabled; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txtLat = (TextView) findViewById(R.id.textview1); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } @Oviewride public void onLocationChanged(Location location) { txtLat = (TextView) findViewById(R.id.textview1); txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude()); } @Oviewride public void onProviderDisabled(String provider) { Log.d("Latitude","disable"); } @Oviewride public void onProviderEnabled(String provider) { Log.d("Latitude","enable"); } @Oviewride public void onStatusChanged(String provider, int status, Bundle extras) { Log.d("Latitude","status"); } } } import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.widget.TextView; import android.util.Log; public class MainActivity extends Activity implements LocationListener{ protected LocationManager locationManager; protected LocationListener locationListener; protected Context context; TextView txtLat; String lat; String provider; protected String latitude,longitude; protected boolean gps_enabled,network_enabled; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txtLat = (TextView) findViewById(R.id.textview1); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } @Oviewride public void onLocationChanged(Location location) { txtLat = (TextView) findViewById(R.id.textview1); txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude()); } @Oviewride public void onProviderDisabled(String provider) { Log.d("Latitude","disable"); } @Oviewride public void onProviderEnabled(String provider) { Log.d("Latitude","enable"); } @Oviewride public void onStatusChanged(String provider, int status, Bundle extras) { Log.d("Latitude","status"); } } 

    Por que não usair FusedLocationApi vez de OnMyLocationChangeListener ? Você precisa inicializair o object GoogleApiClient e usair o método LocationServices.FusedLocationApi.requestLocationUpdates() paira registrair o operador de alterações de localization. É importante notair que não se esqueça de remoview o ouvinte registrado e desconectair o GoogleApiClient .

     private LocationRequest mLocationRequest; private GoogleApiClient mGoogleApiClient; private LocationListener mLocationListener; private void initGoogleApiClient(Context context) { mGoogleApiClient = new GoogleApiClient.Builder(context).addApi(LocationServices.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Oviewride public void onConnected(Bundle bundle) { mLocationRequest = LocationRequest.create(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(1000); setLocationListener(); } @Oviewride public void onConnectionSuspended(int i) { Log.i("LOG_TAG", "onConnectionSuspended"); } }).build(); if (mGoogleApiClient != null) mGoogleApiClient.connect(); } private void setLocationListener() { mLocationListener = new LocationListener() { @Oviewride public void onLocationChanged(Location location) { String lat = String.valueOf(location.getLatitude()); String lon = String.valueOf(location.getLongitude()); Log.i("LOG_TAG", "Latitude = " + lat + " Longitude = " + lon); } }; LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, mLocationListener); } private void removeLocationListener() { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener); } { private LocationRequest mLocationRequest; private GoogleApiClient mGoogleApiClient; private LocationListener mLocationListener; private void initGoogleApiClient(Context context) { mGoogleApiClient = new GoogleApiClient.Builder(context).addApi(LocationServices.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Oviewride public void onConnected(Bundle bundle) { mLocationRequest = LocationRequest.create(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(1000); setLocationListener(); } @Oviewride public void onConnectionSuspended(int i) { Log.i("LOG_TAG", "onConnectionSuspended"); } }).build(); if (mGoogleApiClient != null) mGoogleApiClient.connect(); } private void setLocationListener() { mLocationListener = new LocationListener() { @Oviewride public void onLocationChanged(Location location) { String lat = String.valueOf(location.getLatitude()); String lon = String.valueOf(location.getLongitude()); Log.i("LOG_TAG", "Latitude = " + lat + " Longitude = " + lon); } }; LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, mLocationListener); } private void removeLocationListener() { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener); } { private LocationRequest mLocationRequest; private GoogleApiClient mGoogleApiClient; private LocationListener mLocationListener; private void initGoogleApiClient(Context context) { mGoogleApiClient = new GoogleApiClient.Builder(context).addApi(LocationServices.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Oviewride public void onConnected(Bundle bundle) { mLocationRequest = LocationRequest.create(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(1000); setLocationListener(); } @Oviewride public void onConnectionSuspended(int i) { Log.i("LOG_TAG", "onConnectionSuspended"); } }).build(); if (mGoogleApiClient != null) mGoogleApiClient.connect(); } private void setLocationListener() { mLocationListener = new LocationListener() { @Oviewride public void onLocationChanged(Location location) { String lat = String.valueOf(location.getLatitude()); String lon = String.valueOf(location.getLongitude()); Log.i("LOG_TAG", "Latitude = " + lat + " Longitude = " + lon); } }; LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, mLocationListener); } private void removeLocationListener() { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener); } { private LocationRequest mLocationRequest; private GoogleApiClient mGoogleApiClient; private LocationListener mLocationListener; private void initGoogleApiClient(Context context) { mGoogleApiClient = new GoogleApiClient.Builder(context).addApi(LocationServices.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Oviewride public void onConnected(Bundle bundle) { mLocationRequest = LocationRequest.create(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(1000); setLocationListener(); } @Oviewride public void onConnectionSuspended(int i) { Log.i("LOG_TAG", "onConnectionSuspended"); } }).build(); if (mGoogleApiClient != null) mGoogleApiClient.connect(); } private void setLocationListener() { mLocationListener = new LocationListener() { @Oviewride public void onLocationChanged(Location location) { String lat = String.valueOf(location.getLatitude()); String lon = String.valueOf(location.getLongitude()); Log.i("LOG_TAG", "Latitude = " + lat + " Longitude = " + lon); } }; LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, mLocationListener); } private void removeLocationListener() { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener); } } private LocationRequest mLocationRequest; private GoogleApiClient mGoogleApiClient; private LocationListener mLocationListener; private void initGoogleApiClient(Context context) { mGoogleApiClient = new GoogleApiClient.Builder(context).addApi(LocationServices.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Oviewride public void onConnected(Bundle bundle) { mLocationRequest = LocationRequest.create(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(1000); setLocationListener(); } @Oviewride public void onConnectionSuspended(int i) { Log.i("LOG_TAG", "onConnectionSuspended"); } }).build(); if (mGoogleApiClient != null) mGoogleApiClient.connect(); } private void setLocationListener() { mLocationListener = new LocationListener() { @Oviewride public void onLocationChanged(Location location) { String lat = String.valueOf(location.getLatitude()); String lon = String.valueOf(location.getLongitude()); Log.i("LOG_TAG", "Latitude = " + lat + " Longitude = " + lon); } }; LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, mLocationListener); } private void removeLocationListener() { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener); } { private LocationRequest mLocationRequest; private GoogleApiClient mGoogleApiClient; private LocationListener mLocationListener; private void initGoogleApiClient(Context context) { mGoogleApiClient = new GoogleApiClient.Builder(context).addApi(LocationServices.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Oviewride public void onConnected(Bundle bundle) { mLocationRequest = LocationRequest.create(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(1000); setLocationListener(); } @Oviewride public void onConnectionSuspended(int i) { Log.i("LOG_TAG", "onConnectionSuspended"); } }).build(); if (mGoogleApiClient != null) mGoogleApiClient.connect(); } private void setLocationListener() { mLocationListener = new LocationListener() { @Oviewride public void onLocationChanged(Location location) { String lat = String.valueOf(location.getLatitude()); String lon = String.valueOf(location.getLongitude()); Log.i("LOG_TAG", "Latitude = " + lat + " Longitude = " + lon); } }; LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, mLocationListener); } private void removeLocationListener() { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener); } } private LocationRequest mLocationRequest; private GoogleApiClient mGoogleApiClient; private LocationListener mLocationListener; private void initGoogleApiClient(Context context) { mGoogleApiClient = new GoogleApiClient.Builder(context).addApi(LocationServices.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Oviewride public void onConnected(Bundle bundle) { mLocationRequest = LocationRequest.create(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(1000); setLocationListener(); } @Oviewride public void onConnectionSuspended(int i) { Log.i("LOG_TAG", "onConnectionSuspended"); } }).build(); if (mGoogleApiClient != null) mGoogleApiClient.connect(); } private void setLocationListener() { mLocationListener = new LocationListener() { @Oviewride public void onLocationChanged(Location location) { String lat = String.valueOf(location.getLatitude()); String lon = String.valueOf(location.getLongitude()); Log.i("LOG_TAG", "Latitude = " + lat + " Longitude = " + lon); } }; LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, mLocationListener); } private void removeLocationListener() { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener); } } private LocationRequest mLocationRequest; private GoogleApiClient mGoogleApiClient; private LocationListener mLocationListener; private void initGoogleApiClient(Context context) { mGoogleApiClient = new GoogleApiClient.Builder(context).addApi(LocationServices.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Oviewride public void onConnected(Bundle bundle) { mLocationRequest = LocationRequest.create(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(1000); setLocationListener(); } @Oviewride public void onConnectionSuspended(int i) { Log.i("LOG_TAG", "onConnectionSuspended"); } }).build(); if (mGoogleApiClient != null) mGoogleApiClient.connect(); } private void setLocationListener() { mLocationListener = new LocationListener() { @Oviewride public void onLocationChanged(Location location) { String lat = String.valueOf(location.getLatitude()); String lon = String.valueOf(location.getLongitude()); Log.i("LOG_TAG", "Latitude = " + lat + " Longitude = " + lon); } }; LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, mLocationListener); } private void removeLocationListener() { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener); } { private LocationRequest mLocationRequest; private GoogleApiClient mGoogleApiClient; private LocationListener mLocationListener; private void initGoogleApiClient(Context context) { mGoogleApiClient = new GoogleApiClient.Builder(context).addApi(LocationServices.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Oviewride public void onConnected(Bundle bundle) { mLocationRequest = LocationRequest.create(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(1000); setLocationListener(); } @Oviewride public void onConnectionSuspended(int i) { Log.i("LOG_TAG", "onConnectionSuspended"); } }).build(); if (mGoogleApiClient != null) mGoogleApiClient.connect(); } private void setLocationListener() { mLocationListener = new LocationListener() { @Oviewride public void onLocationChanged(Location location) { String lat = String.valueOf(location.getLatitude()); String lon = String.valueOf(location.getLongitude()); Log.i("LOG_TAG", "Latitude = " + lat + " Longitude = " + lon); } }; LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, mLocationListener); } private void removeLocationListener() { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener); } { private LocationRequest mLocationRequest; private GoogleApiClient mGoogleApiClient; private LocationListener mLocationListener; private void initGoogleApiClient(Context context) { mGoogleApiClient = new GoogleApiClient.Builder(context).addApi(LocationServices.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Oviewride public void onConnected(Bundle bundle) { mLocationRequest = LocationRequest.create(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(1000); setLocationListener(); } @Oviewride public void onConnectionSuspended(int i) { Log.i("LOG_TAG", "onConnectionSuspended"); } }).build(); if (mGoogleApiClient != null) mGoogleApiClient.connect(); } private void setLocationListener() { mLocationListener = new LocationListener() { @Oviewride public void onLocationChanged(Location location) { String lat = String.valueOf(location.getLatitude()); String lon = String.valueOf(location.getLongitude()); Log.i("LOG_TAG", "Latitude = " + lat + " Longitude = " + lon); } }; LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, mLocationListener); } private void removeLocationListener() { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener); } { private LocationRequest mLocationRequest; private GoogleApiClient mGoogleApiClient; private LocationListener mLocationListener; private void initGoogleApiClient(Context context) { mGoogleApiClient = new GoogleApiClient.Builder(context).addApi(LocationServices.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Oviewride public void onConnected(Bundle bundle) { mLocationRequest = LocationRequest.create(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(1000); setLocationListener(); } @Oviewride public void onConnectionSuspended(int i) { Log.i("LOG_TAG", "onConnectionSuspended"); } }).build(); if (mGoogleApiClient != null) mGoogleApiClient.connect(); } private void setLocationListener() { mLocationListener = new LocationListener() { @Oviewride public void onLocationChanged(Location location) { String lat = String.valueOf(location.getLatitude()); String lon = String.valueOf(location.getLongitude()); Log.i("LOG_TAG", "Latitude = " + lat + " Longitude = " + lon); } }; LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, mLocationListener); } private void removeLocationListener() { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener); } } private LocationRequest mLocationRequest; private GoogleApiClient mGoogleApiClient; private LocationListener mLocationListener; private void initGoogleApiClient(Context context) { mGoogleApiClient = new GoogleApiClient.Builder(context).addApi(LocationServices.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Oviewride public void onConnected(Bundle bundle) { mLocationRequest = LocationRequest.create(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(1000); setLocationListener(); } @Oviewride public void onConnectionSuspended(int i) { Log.i("LOG_TAG", "onConnectionSuspended"); } }).build(); if (mGoogleApiClient != null) mGoogleApiClient.connect(); } private void setLocationListener() { mLocationListener = new LocationListener() { @Oviewride public void onLocationChanged(Location location) { String lat = String.valueOf(location.getLatitude()); String lon = String.valueOf(location.getLongitude()); Log.i("LOG_TAG", "Latitude = " + lat + " Longitude = " + lon); } }; LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, mLocationListener); } private void removeLocationListener() { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener); } }; private LocationRequest mLocationRequest; private GoogleApiClient mGoogleApiClient; private LocationListener mLocationListener; private void initGoogleApiClient(Context context) { mGoogleApiClient = new GoogleApiClient.Builder(context).addApi(LocationServices.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Oviewride public void onConnected(Bundle bundle) { mLocationRequest = LocationRequest.create(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(1000); setLocationListener(); } @Oviewride public void onConnectionSuspended(int i) { Log.i("LOG_TAG", "onConnectionSuspended"); } }).build(); if (mGoogleApiClient != null) mGoogleApiClient.connect(); } private void setLocationListener() { mLocationListener = new LocationListener() { @Oviewride public void onLocationChanged(Location location) { String lat = String.valueOf(location.getLatitude()); String lon = String.valueOf(location.getLongitude()); Log.i("LOG_TAG", "Latitude = " + lat + " Longitude = " + lon); } }; LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, mLocationListener); } private void removeLocationListener() { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener); } } private LocationRequest mLocationRequest; private GoogleApiClient mGoogleApiClient; private LocationListener mLocationListener; private void initGoogleApiClient(Context context) { mGoogleApiClient = new GoogleApiClient.Builder(context).addApi(LocationServices.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Oviewride public void onConnected(Bundle bundle) { mLocationRequest = LocationRequest.create(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(1000); setLocationListener(); } @Oviewride public void onConnectionSuspended(int i) { Log.i("LOG_TAG", "onConnectionSuspended"); } }).build(); if (mGoogleApiClient != null) mGoogleApiClient.connect(); } private void setLocationListener() { mLocationListener = new LocationListener() { @Oviewride public void onLocationChanged(Location location) { String lat = String.valueOf(location.getLatitude()); String lon = String.valueOf(location.getLongitude()); Log.i("LOG_TAG", "Latitude = " + lat + " Longitude = " + lon); } }; LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, mLocationListener); } private void removeLocationListener() { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener); } { private LocationRequest mLocationRequest; private GoogleApiClient mGoogleApiClient; private LocationListener mLocationListener; private void initGoogleApiClient(Context context) { mGoogleApiClient = new GoogleApiClient.Builder(context).addApi(LocationServices.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Oviewride public void onConnected(Bundle bundle) { mLocationRequest = LocationRequest.create(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(1000); setLocationListener(); } @Oviewride public void onConnectionSuspended(int i) { Log.i("LOG_TAG", "onConnectionSuspended"); } }).build(); if (mGoogleApiClient != null) mGoogleApiClient.connect(); } private void setLocationListener() { mLocationListener = new LocationListener() { @Oviewride public void onLocationChanged(Location location) { String lat = String.valueOf(location.getLatitude()); String lon = String.valueOf(location.getLongitude()); Log.i("LOG_TAG", "Latitude = " + lat + " Longitude = " + lon); } }; LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, mLocationListener); } private void removeLocationListener() { LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener); } 
     public class MainActivity extends ActionBairActivity implements ConnectionCallbacks, OnConnectionFailedListener { ... @Oviewride public void onConnected(Bundle connectionHint) { mLastLocation = LocationServices.FusedLocationApi.getLastLocation( mGoogleApiClient); if (mLastLocation != null) { mLatitudeText.setText(String.valueOf(mLastLocation.getLatitude())); mLongitudeText.setText(String.valueOf(mLastLocation.getLongitude())); } } } ... public class MainActivity extends ActionBairActivity implements ConnectionCallbacks, OnConnectionFailedListener { ... @Oviewride public void onConnected(Bundle connectionHint) { mLastLocation = LocationServices.FusedLocationApi.getLastLocation( mGoogleApiClient); if (mLastLocation != null) { mLatitudeText.setText(String.valueOf(mLastLocation.getLatitude())); mLongitudeText.setText(String.valueOf(mLastLocation.getLongitude())); } } } } public class MainActivity extends ActionBairActivity implements ConnectionCallbacks, OnConnectionFailedListener { ... @Oviewride public void onConnected(Bundle connectionHint) { mLastLocation = LocationServices.FusedLocationApi.getLastLocation( mGoogleApiClient); if (mLastLocation != null) { mLatitudeText.setText(String.valueOf(mLastLocation.getLatitude())); mLongitudeText.setText(String.valueOf(mLastLocation.getLongitude())); } } } } public class MainActivity extends ActionBairActivity implements ConnectionCallbacks, OnConnectionFailedListener { ... @Oviewride public void onConnected(Bundle connectionHint) { mLastLocation = LocationServices.FusedLocationApi.getLastLocation( mGoogleApiClient); if (mLastLocation != null) { mLatitudeText.setText(String.valueOf(mLastLocation.getLatitude())); mLongitudeText.setText(String.valueOf(mLastLocation.getLongitude())); } } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.