Note that there are some explanatory texts on larger screens.

plurals
  1. POgetLastKnownLocation() always returning null, all providers are DummyLocationProvider
    primarykey
    data
    text
    <p>I have seen many posts regarding this problem, but none of them offered a solution for me.</p> <p>I am trying to get the user position through the GPS (or, ultimately, any other valid provider). But I am always getting null locations. I do get a map, and can set an arbitrary location, is the providers that don't work.</p> <p><strong>I have my MAPS key properly set</strong> (also checked that it was the right one), all necessary permissions set (<code>android.permission.INTERNET</code>, <code>android.permission.ACCESS_COARSE_LOCATION</code>, <code>android.permission.ACCESS_FINE_LOCATION</code>) and in fact, all seemed to be working just fine yesterday!</p> <p>I tried getting all possible providers with this code:</p> <pre><code>List&lt;String&gt; providers = locManager.getAllProviders(); for (String provider : providers) { printProvider(provider); } </code></pre> <p>Which shows all providers (4, in my case) are DummyLocationProviders.</p> <p>I am trying to run my app <strong>on the phone, not the emulator</strong> (although I also tried with the emulator, with GPS enabled, to no avail).</p> <p>This is the code I am using to fetch the location (which, again, worked just fine yesterday):</p> <pre><code>//Get criteria Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); //Get best provider String bestProvider = locManager.getBestProvider(criteria, false); printProvider(bestProvider); //get the current location (last known location) from the location manager Location location = locManager.getLastKnownLocation(bestProvider); //if location found display as a toast the current latitude and longitude if (location != null) { Toast.makeText(this, "Current location:\nLatitude: " + location.getLatitude() + "\n" + "Longitude: " + location.getLongitude(), Toast.LENGTH_LONG).show(); point = new GeoPoint((int) (location.getLatitude()*1E6),(int)(location.getLongitude() *1E6)); controller.animateTo(point); } else { Toast.makeText(this, "Cannot fetch current location!", Toast.LENGTH_LONG).show(); } </code></pre> <p>My manifest file: </p> <pre><code> &lt;uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10" /&gt; &lt;uses-permission android:name="android.permission.INTERNET"/&gt; &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name=".activities.MainActivity" android:label="@string/title_activity_main" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;uses-library android:name="com.google.android.maps" /&gt; &lt;activity android:name=".activities.GoogleMapsActivity" android:label="@string/title_activity_maps" &gt; &lt;/activity&gt; &lt;activity android:name=".activities.MyMapsActivity" android:label="@string/title_activity_maps" &gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </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