Note that there are some explanatory texts on larger screens.

plurals
  1. POI cannot get GPS coordinates
    primarykey
    data
    text
    <p>My problem is that I cannot get GPS coordinates by using LocationManager class and LocationListener. This is the code I call in OnCreate():</p> <pre><code> locMgr = (LocationManager)getSystemService(Context.LOCATION_SERVICE); currentLocListener = new MyLocationListener(); locMgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, currentLocListener); locMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, currentLocListener); </code></pre> <p>And I have a class MyLocationListener that implements class LocationListener</p> <pre><code>public class MyLocationListener implements LocationListener { @Override public void onLocationChanged(Location location) { // TODO Auto-generated method stub String coordinates[] = {""+location.getLatitude(),""+location.getLongitude()}; double lat = Double.parseDouble(coordinates[0]); double lng = Double.parseDouble(coordinates[1]); GeoPoint p = new GeoPoint((int)(lat*1E6), (int)(lng*1E6)); mc.animateTo(p); mc.setZoom(19); MyMapOverlays marker = new MyMapOverlays(p); List&lt;Overlay&gt; listofOverLays = mapview.getOverlays(); listofOverLays.clear(); listofOverLays.add(marker); mapview.invalidate(); } @Override public void onProviderDisabled(String provider) { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), "GPS is disabled", Toast.LENGTH_SHORT).show(); } @Override public void onProviderEnabled(String provider) { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), "GPS is Enabled", Toast.LENGTH_SHORT).show(); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub }} </code></pre> <p>I can get the location by mocking location in Emulator Control in DDMS. So I try to test on my real phone. when I install it on my phone, it can't get the current location automatically although I turned on GPS and wifi.</p> <p>I try to run another google map app from market on to my real phone, it worked fine. I don't understand what is wrong with the code...can anyone help me?</p> <p><b>LOGCAT &amp; DEBUG</b></p> <pre><code>DalvikVM[localhost:8631] Thread [&lt;1&gt; main] (Suspended (exception NullPointerException)) DashboardActivity$MyLocationListener.onLocationChanged(Location) line: 75 LocationManager$ListenerTransport._handleMessage(Message) line: 191 LocationManager$ListenerTransport.access$000(LocationManager$ListenerTransport, Message) line: 124 LocationManager$ListenerTransport$1.handleMessage(Message) line: 140 LocationManager$ListenerTransport$1(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 4627 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 ZygoteInit$MethodAndArgsCaller.run() line: 868 ZygoteInit.main(String[]) line: 626 NativeStart.main(String[]) line: not available [native method] Thread [&lt;6&gt; Binder Thread #2] (Running) Thread [&lt;5&gt; Binder Thread #1] (Running) Thread [&lt;7&gt; MapService] (Running) Thread [&lt;8&gt; TrafficService] (Running) Daemon Thread [&lt;10&gt; RefQueueWorker@org.apache.http.impl.conn.tsccm.ConnPoolByRoute@4610b970] (Running) </code></pre> <p>LINE 75 giving error.</p>
    singulars
    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.
    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