Note that there are some explanatory texts on larger screens.

plurals
  1. POFailed to get may location using GPS at android?
    primarykey
    data
    text
    <p>This is my code. I tried to get my location using GPS, it returns the latitude and longitude but the list of addresses I required to return doesn't return. What should I do ?</p> <p>Does anyone have a best updated method at android to get my location using GPS?</p> <pre><code>package com.locDetermine; import java.io.IOException; import java.util.List; import java.util.Locale; import android.app.Activity; import android.content.Context; import android.location.Address; import android.location.Geocoder; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.util.Log; import android.widget.TextView; import android.widget.Toast; public class LocDetermineActivity extends Activity implements LocationListener{ /** Called when the activity is first created. */ LocationManager locationManager = null; Location location = null; TextView tvLocation ; Geocoder geo ; //GeoPoint point ; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tvLocation = (TextView) findViewById(R.id.tv_loc); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 10, this); } @Override public void onLocationChanged(Location location) { // TODO Auto-generated method stub double latitude = location.getLatitude(); double longitude = location.getLongitude(); geo = new Geocoder(getApplicationContext(), Locale.getDefault()); //tvLocation.setText( "Location change : Latitude :"+latitude+"Longitude :"+longitude); location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if(location != null) { Toast.makeText(getApplicationContext(), "Location found", Toast.LENGTH_LONG).show(); try { List&lt;Address&gt; addresses = geo.getFromLocation(latitude, longitude, 5); String add = ""; if(addresses.size() &gt; 0) { for(int i =0; i&lt;addresses.get(0).getMaxAddressLineIndex(); i++) add += addresses.get(0).getAddressLine(i); } tvLocation.append("\n"+add); } catch (IOException e) { Log.e("Where u !", "Didn't get it!",e); } } else Toast.makeText(getApplicationContext(), "Location not found", Toast.LENGTH_LONG).show(); } @Override public void onProviderDisabled(String arg0) { // TODO Auto-generated method stub } @Override public void onProviderEnabled(String arg0) { // TODO Auto-generated method stub } @Override public void onStatusChanged(String arg0, int arg1, Bundle arg2) { // TODO Auto-generated method stub } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload