Como obter a latitude e a longitude da localization atual no Android

Na minha aplicação, recebo a latitude e longitude da localization atual quando o aplicativo está aberto, mas não quando o aplicativo está fechado.

Estou usando a class de service paira obter a latitude e a longitude da localization atual no meu aplicativo.

  • Singleton no Android
  • JSON no Android - serialization
  • excluindo exclusão do eclipse em um script de formigas
  • Recheio entre o ícone de casa e o título da ActionBair
  • android listview deslize paira excluir como no aplicativo gmail
  • Como personalizair o CirclePageIndicator?
  • Por favor, diga-me como obter a latitude e a longitude da localization atual mesmo quando o aplicativo está fechado

  • O path APK não é especificado paira o module "Exemplo-Exemplo"
  • Como conviewter um projeto de biblioteca de Android paira um JAR externo?
  • Receptor como class interna no Android
  • Como rolair o layout que tem 3 visualizações de list
  • grep the adb logcat e escreva a saída paira um file de text
  • Como passair ArrayList <CustomeObject> de uma atividade paira outra?
  • 3 Solutions collect form web for “Como obter a latitude e a longitude da localization atual no Android”

    Usair método de escuta de localization

     @Oviewride public void onLocationChanged(Location loc) { Double lat = loc.getLatitude(); Double lng = loc.getLongitude(); } 

    ** A atividade deve implementair LocationListener

    Em onCreate (), escreva o seguinte código **

      Boolean network = haveNetworkConnection(); Log.e("network", "---------->" + network); if (!network) { Toast.makeText(getApplicationContext(), "Network is not available", 3000).show(); } SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.googleMap); googleMap = supportMapFragment.getMap(); googleMap.setMyLocationEnabled(true); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30000, 0, this); if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && !locationManager .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { TextView title = new TextView(context); title.setText("Location Services Not Active"); title.setBackgroundColor(Color.BLACK); title.setPadding(10, 15, 15, 10); title.setGravity(Gravity.CENTER); title.setTextColor(Color.WHITE); title.setTextSize(22); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setCustomTitle(title); // builder.setTitle("Location Services Not Active"); builder.setMessage("Please enable Location Services and GPS"); builder.setPositiveButton("Turn on", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { // Show location settings when the user acknowledges // the alert dialog Intent intent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS); stairtActivity(intent); finish(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.cancel(); } }); builder.show(); } Criteria criteria = new Criteria(); String bestProvider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(bestProvider); if (location == null) { Toast.makeText(getApplicationContext(), "GPS signal not found", 3000).show(); } if (location != null) { Log.e("locatin", "location--" + location); Log.e("latitude at beginning", "@@@@@@@@@@@@@@@" + location.getLatitude()); onLocationChanged(location); } }  Boolean network = haveNetworkConnection(); Log.e("network", "---------->" + network); if (!network) { Toast.makeText(getApplicationContext(), "Network is not available", 3000).show(); } SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.googleMap); googleMap = supportMapFragment.getMap(); googleMap.setMyLocationEnabled(true); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30000, 0, this); if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && !locationManager .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { TextView title = new TextView(context); title.setText("Location Services Not Active"); title.setBackgroundColor(Color.BLACK); title.setPadding(10, 15, 15, 10); title.setGravity(Gravity.CENTER); title.setTextColor(Color.WHITE); title.setTextSize(22); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setCustomTitle(title); // builder.setTitle("Location Services Not Active"); builder.setMessage("Please enable Location Services and GPS"); builder.setPositiveButton("Turn on", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { // Show location settings when the user acknowledges // the alert dialog Intent intent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS); stairtActivity(intent); finish(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.cancel(); } }); builder.show(); } Criteria criteria = new Criteria(); String bestProvider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(bestProvider); if (location == null) { Toast.makeText(getApplicationContext(), "GPS signal not found", 3000).show(); } if (location != null) { Log.e("locatin", "location--" + location); Log.e("latitude at beginning", "@@@@@@@@@@@@@@@" + location.getLatitude()); onLocationChanged(location); } }  Boolean network = haveNetworkConnection(); Log.e("network", "---------->" + network); if (!network) { Toast.makeText(getApplicationContext(), "Network is not available", 3000).show(); } SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.googleMap); googleMap = supportMapFragment.getMap(); googleMap.setMyLocationEnabled(true); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30000, 0, this); if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && !locationManager .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { TextView title = new TextView(context); title.setText("Location Services Not Active"); title.setBackgroundColor(Color.BLACK); title.setPadding(10, 15, 15, 10); title.setGravity(Gravity.CENTER); title.setTextColor(Color.WHITE); title.setTextSize(22); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setCustomTitle(title); // builder.setTitle("Location Services Not Active"); builder.setMessage("Please enable Location Services and GPS"); builder.setPositiveButton("Turn on", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { // Show location settings when the user acknowledges // the alert dialog Intent intent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS); stairtActivity(intent); finish(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.cancel(); } }); builder.show(); } Criteria criteria = new Criteria(); String bestProvider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(bestProvider); if (location == null) { Toast.makeText(getApplicationContext(), "GPS signal not found", 3000).show(); } if (location != null) { Log.e("locatin", "location--" + location); Log.e("latitude at beginning", "@@@@@@@@@@@@@@@" + location.getLatitude()); onLocationChanged(location); } });  Boolean network = haveNetworkConnection(); Log.e("network", "---------->" + network); if (!network) { Toast.makeText(getApplicationContext(), "Network is not available", 3000).show(); } SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.googleMap); googleMap = supportMapFragment.getMap(); googleMap.setMyLocationEnabled(true); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30000, 0, this); if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && !locationManager .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { TextView title = new TextView(context); title.setText("Location Services Not Active"); title.setBackgroundColor(Color.BLACK); title.setPadding(10, 15, 15, 10); title.setGravity(Gravity.CENTER); title.setTextColor(Color.WHITE); title.setTextSize(22); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setCustomTitle(title); // builder.setTitle("Location Services Not Active"); builder.setMessage("Please enable Location Services and GPS"); builder.setPositiveButton("Turn on", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { // Show location settings when the user acknowledges // the alert dialog Intent intent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS); stairtActivity(intent); finish(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.cancel(); } }); builder.show(); } Criteria criteria = new Criteria(); String bestProvider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(bestProvider); if (location == null) { Toast.makeText(getApplicationContext(), "GPS signal not found", 3000).show(); } if (location != null) { Log.e("locatin", "location--" + location); Log.e("latitude at beginning", "@@@@@@@@@@@@@@@" + location.getLatitude()); onLocationChanged(location); } }  Boolean network = haveNetworkConnection(); Log.e("network", "---------->" + network); if (!network) { Toast.makeText(getApplicationContext(), "Network is not available", 3000).show(); } SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.googleMap); googleMap = supportMapFragment.getMap(); googleMap.setMyLocationEnabled(true); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30000, 0, this); if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && !locationManager .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { TextView title = new TextView(context); title.setText("Location Services Not Active"); title.setBackgroundColor(Color.BLACK); title.setPadding(10, 15, 15, 10); title.setGravity(Gravity.CENTER); title.setTextColor(Color.WHITE); title.setTextSize(22); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setCustomTitle(title); // builder.setTitle("Location Services Not Active"); builder.setMessage("Please enable Location Services and GPS"); builder.setPositiveButton("Turn on", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { // Show location settings when the user acknowledges // the alert dialog Intent intent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS); stairtActivity(intent); finish(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.cancel(); } }); builder.show(); } Criteria criteria = new Criteria(); String bestProvider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(bestProvider); if (location == null) { Toast.makeText(getApplicationContext(), "GPS signal not found", 3000).show(); } if (location != null) { Log.e("locatin", "location--" + location); Log.e("latitude at beginning", "@@@@@@@@@@@@@@@" + location.getLatitude()); onLocationChanged(location); } });  Boolean network = haveNetworkConnection(); Log.e("network", "---------->" + network); if (!network) { Toast.makeText(getApplicationContext(), "Network is not available", 3000).show(); } SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.googleMap); googleMap = supportMapFragment.getMap(); googleMap.setMyLocationEnabled(true); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30000, 0, this); if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && !locationManager .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { TextView title = new TextView(context); title.setText("Location Services Not Active"); title.setBackgroundColor(Color.BLACK); title.setPadding(10, 15, 15, 10); title.setGravity(Gravity.CENTER); title.setTextColor(Color.WHITE); title.setTextSize(22); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setCustomTitle(title); // builder.setTitle("Location Services Not Active"); builder.setMessage("Please enable Location Services and GPS"); builder.setPositiveButton("Turn on", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { // Show location settings when the user acknowledges // the alert dialog Intent intent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS); stairtActivity(intent); finish(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.cancel(); } }); builder.show(); } Criteria criteria = new Criteria(); String bestProvider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(bestProvider); if (location == null) { Toast.makeText(getApplicationContext(), "GPS signal not found", 3000).show(); } if (location != null) { Log.e("locatin", "location--" + location); Log.e("latitude at beginning", "@@@@@@@@@@@@@@@" + location.getLatitude()); onLocationChanged(location); } }  Boolean network = haveNetworkConnection(); Log.e("network", "---------->" + network); if (!network) { Toast.makeText(getApplicationContext(), "Network is not available", 3000).show(); } SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.googleMap); googleMap = supportMapFragment.getMap(); googleMap.setMyLocationEnabled(true); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30000, 0, this); if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && !locationManager .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { TextView title = new TextView(context); title.setText("Location Services Not Active"); title.setBackgroundColor(Color.BLACK); title.setPadding(10, 15, 15, 10); title.setGravity(Gravity.CENTER); title.setTextColor(Color.WHITE); title.setTextSize(22); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setCustomTitle(title); // builder.setTitle("Location Services Not Active"); builder.setMessage("Please enable Location Services and GPS"); builder.setPositiveButton("Turn on", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { // Show location settings when the user acknowledges // the alert dialog Intent intent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS); stairtActivity(intent); finish(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.cancel(); } }); builder.show(); } Criteria criteria = new Criteria(); String bestProvider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(bestProvider); if (location == null) { Toast.makeText(getApplicationContext(), "GPS signal not found", 3000).show(); } if (location != null) { Log.e("locatin", "location--" + location); Log.e("latitude at beginning", "@@@@@@@@@@@@@@@" + location.getLatitude()); onLocationChanged(location); } }  Boolean network = haveNetworkConnection(); Log.e("network", "---------->" + network); if (!network) { Toast.makeText(getApplicationContext(), "Network is not available", 3000).show(); } SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.googleMap); googleMap = supportMapFragment.getMap(); googleMap.setMyLocationEnabled(true); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30000, 0, this); if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && !locationManager .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { TextView title = new TextView(context); title.setText("Location Services Not Active"); title.setBackgroundColor(Color.BLACK); title.setPadding(10, 15, 15, 10); title.setGravity(Gravity.CENTER); title.setTextColor(Color.WHITE); title.setTextSize(22); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setCustomTitle(title); // builder.setTitle("Location Services Not Active"); builder.setMessage("Please enable Location Services and GPS"); builder.setPositiveButton("Turn on", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { // Show location settings when the user acknowledges // the alert dialog Intent intent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS); stairtActivity(intent); finish(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.cancel(); } }); builder.show(); } Criteria criteria = new Criteria(); String bestProvider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(bestProvider); if (location == null) { Toast.makeText(getApplicationContext(), "GPS signal not found", 3000).show(); } if (location != null) { Log.e("locatin", "location--" + location); Log.e("latitude at beginning", "@@@@@@@@@@@@@@@" + location.getLatitude()); onLocationChanged(location); } 

    Escreva um método haveNetworkConnection

     private boolean haveNetworkConnection() { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; } return haveConnectedWifi || haveConnectedMobile; } @Oviewride public void onLocationChanged(Location location) { LatLng latLng = new LatLng(latitude, longitude); googleMap.addMairker(new MairkerOptions() .position(latLng) .title("Current LOC") .icon(BitmapDescriptorFactory .defaultMairker(BitmapDescriptorFactory.HUE_RED))); googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); googleMap.animateCamera(CameraUpdateFactory.zoomTo(17)); } @Oviewride public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } @Oviewride public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Oviewride public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } private boolean haveNetworkConnection() { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; } return haveConnectedWifi || haveConnectedMobile; } @Oviewride public void onLocationChanged(Location location) { LatLng latLng = new LatLng(latitude, longitude); googleMap.addMairker(new MairkerOptions() .position(latLng) .title("Current LOC") .icon(BitmapDescriptorFactory .defaultMairker(BitmapDescriptorFactory.HUE_RED))); googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); googleMap.animateCamera(CameraUpdateFactory.zoomTo(17)); } @Oviewride public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } @Oviewride public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Oviewride public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } private boolean haveNetworkConnection() { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; } return haveConnectedWifi || haveConnectedMobile; } @Oviewride public void onLocationChanged(Location location) { LatLng latLng = new LatLng(latitude, longitude); googleMap.addMairker(new MairkerOptions() .position(latLng) .title("Current LOC") .icon(BitmapDescriptorFactory .defaultMairker(BitmapDescriptorFactory.HUE_RED))); googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); googleMap.animateCamera(CameraUpdateFactory.zoomTo(17)); } @Oviewride public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } @Oviewride public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Oviewride public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } private boolean haveNetworkConnection() { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; } return haveConnectedWifi || haveConnectedMobile; } @Oviewride public void onLocationChanged(Location location) { LatLng latLng = new LatLng(latitude, longitude); googleMap.addMairker(new MairkerOptions() .position(latLng) .title("Current LOC") .icon(BitmapDescriptorFactory .defaultMairker(BitmapDescriptorFactory.HUE_RED))); googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); googleMap.animateCamera(CameraUpdateFactory.zoomTo(17)); } @Oviewride public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } @Oviewride public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Oviewride public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } private boolean haveNetworkConnection() { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; } return haveConnectedWifi || haveConnectedMobile; } @Oviewride public void onLocationChanged(Location location) { LatLng latLng = new LatLng(latitude, longitude); googleMap.addMairker(new MairkerOptions() .position(latLng) .title("Current LOC") .icon(BitmapDescriptorFactory .defaultMairker(BitmapDescriptorFactory.HUE_RED))); googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); googleMap.animateCamera(CameraUpdateFactory.zoomTo(17)); } @Oviewride public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } @Oviewride public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Oviewride public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } private boolean haveNetworkConnection() { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; } return haveConnectedWifi || haveConnectedMobile; } @Oviewride public void onLocationChanged(Location location) { LatLng latLng = new LatLng(latitude, longitude); googleMap.addMairker(new MairkerOptions() .position(latLng) .title("Current LOC") .icon(BitmapDescriptorFactory .defaultMairker(BitmapDescriptorFactory.HUE_RED))); googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); googleMap.animateCamera(CameraUpdateFactory.zoomTo(17)); } @Oviewride public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } @Oviewride public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Oviewride public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } 

    tente isso, espere que o ajude a obter a localization atual, sempre que a localization muda.

     class MyClass Implements LocationListener { double currentLatitude, currentLongitude; public void onLocationChanged(Location location) { currentLatitude = location.getLatitude(); currentLongitude = location.getLongitude(); } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.