Note that there are some explanatory texts on larger screens.

plurals
  1. POLocationManager requestLocationUpdates doesn't work
    primarykey
    data
    text
    <p>I'm trying to get the current location in android using LocationManager and LocationListener as described at <a href="http://developer.android.com/guide/topics/location/obtaining-user-location.html" rel="nofollow">http://developer.android.com/guide/topics/location/obtaining-user-location.html</a> </p> <p>However, onLocationChanged method of the LocationListener is never called. I've used a real android phone / also used the emulator and simulated location changed using telnet, as described in the link above.</p> <p>Here's my code:</p> <pre><code>public class MyActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); /* Use the LocationManager class to obtain GPS locations */ LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); LocationListener mlocListener = new CustomLocationListener( getApplicationContext()); // Location Providers String locationProvider = LocationManager.NETWORK_PROVIDER; // LocationProvider locationProvider = LocationManager.GPS_PROVIDER; mlocManager .requestLocationUpdates(locationProvider, 0, 0, mlocListener); } } </code></pre> <p>and my LocationListener: </p> <pre><code>public class CustomLocationListener implements LocationListener { private Context m_context; public CustomLocationListener(Context context) { m_context = context; } @Override public void onLocationChanged(Location location) { double latitude = location.getLatitude(); double longitude = location.getLongitude(); String Text = latitude + " " + longitude; Toast.makeText(m_context, Text, Toast.LENGTH_SHORT).show(); } @Override public void onProviderDisabled(String provider) { // TODO } @Override public void onProviderEnabled(String provider) { // TODO } @Override public void onStatusChanged(String arg0, int arg1, Bundle arg2) {} } </code></pre> <p>So onLocationChanged is never called. Can anyone see the problem?? Thanks a lot</p>
    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