Hai qualche Consiglio/Critica/Suggerimento relativo al forum? Diccelo qui.Ti entusiasma l'idea di un forum italiano di Android? Vorresti partecipare in qualche modo?Scrivi un Tutorial o fai richiesta di ammissione nello Staff
// Otteniamo il riferimento al LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Verifichiamo se il GPS è abilitato altrimenti avvisiamo l'utente if(!locationManager.isProviderEnabled("gps")){ Toast.makeText(this, "GPS è attualmente disabilitato. E' possibile abilitarlo dal menu impostazioni.", Toast.LENGTH_LONG).show(); } // Registriamo il LocationListener al provider GPS locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); } LocationListener locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { // Aggiorna la location Double geoLat = location.getLatitude()*1E6; Double geoLng = location.getLongitude()*1E6; TextView tv = (TextView) findViewById(R.id.widget158); tv.setText(geoLat.toString()); }
Geocoder myLocation = new Geocoder(getApplicationContext(), Locale.getDefault()); List<Address> myList = myLocation.getFromLocation(latPoint, lngPoint, 1);
<uses-permission android:name="android.permission.INTERNET" />
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Otteniamo il riferimento al LocationManager LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Verifichiamo se il GPS è abilitato altrimenti avvisiamo l'utente if(!locationManager.isProviderEnabled("gps")){ Toast.makeText(this, "GPS è attualmente disabilitato. E' possibile abilitarlo dal menu impostazioni.", Toast.LENGTH_LONG).show(); } // Registriamo il LocationListener al provider GPS locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); } LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { if (location != null) { double lat = location.getLatitude(); double lng = location.getLongitude(); Geocoder gc = new Geocoder(getApplicationContext(), Locale.getDefault()); try { List<Address> addresses = gc.getFromLocation(lat, lng, 1); StringBuilder sb = new StringBuilder(); if (addresses.size() > 0) { Address address = addresses.get(0); sb.append(address.getLocality()).append("\n"); sb.append(address.getCountryName()); } System.out.println(sb.toString()); } catch (IOException e) {} } else { //No location found } } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } };
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
Risolto pure il crash se non hai attivo il gps
LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { if (location != null) { double lat = location.getLatitude(); double lng = location.getLongitude(); Geocoder gc = new Geocoder(getApplicationContext(), Locale.getDefault()); try { List<Address> addresses = gc.getFromLocation(lat, lng, 1); StringBuilder sb = new StringBuilder(); if (addresses.size() > 0) { Address address = addresses.get(0); sb.append(address.getLocality()).append("\n"); sb.append(address.getCountryName()); } TextView ecco_dove_sono=(TextView)findViewById(R.id.TextView01); ecco_dove_sono.setText(sb.toString()); System.out.println(sb.toString()); } catch (IOException e) {} } else { //No location found } } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub }