Note that there are some explanatory texts on larger screens.

plurals
  1. POonLocationChanged has not been called
    primarykey
    data
    text
    <p>i've been trying to create a map-related android app, but i realized that the onLocationChanged of my app had not been called, therefore the map always stay at the default area (US).</p> <p>my code:</p> <pre><code>public class MapMainActivity extends MapActivity implements OnClickListener, LocationListener { MapView mapView; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map_main); //reference mapView = (MapView)findViewById(R.id.map_view); mapView.setBuiltInZoomControls(true); this.findViewById(R.id.btn_satellite).setOnClickListener(this); this.findViewById(R.id.btn_street).setOnClickListener(this); }//onCreate @Override protected void onResume() { super.onResume(); Toast.makeText(this, "GPS tracking started", Toast.LENGTH_SHORT).show(); // Start location updates; 5s/5m LocationManager locManager = (LocationManager)getSystemService( Context.LOCATION_SERVICE); locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 0, this); Criteria crit = new Criteria(); crit.setAccuracy(Criteria.ACCURACY_FINE); String provider = locManager.getBestProvider(crit, true); Location loc = locManager.getLastKnownLocation(provider); }//onResume @Override protected void onPause() { super.onPause(); Toast.makeText(this, "GPS tracking stopped", Toast.LENGTH_SHORT).show(); LocationManager locManager = (LocationManager)getSystemService( Context.LOCATION_SERVICE); locManager.removeUpdates(this); }//onPause @Override public void onClick(View v) { // TODO Auto-generated method stub if(v == findViewById(R.id.btn_street)) { mapView.setSatellite(false); }//street view else if (v == findViewById(R.id.btn_satellite)) { mapView.setSatellite(true); } }//onClick @Override protected boolean isRouteDisplayed() { // TODO Auto-generated method stub return false; }//isRouteDisplayed @Override public void onLocationChanged(Location location) { // TODO Auto-generated method stub double lat = location.getLatitude(); double lon = location.getLongitude(); TextView txtLat = (TextView)findViewById(R.id.txt_lat); txtLat.setText(String.format("%.6f", lat)); TextView txtLon = (TextView)findViewById(R.id.txt_lon); txtLon.setText(String.format("%.6f", lon)); MapView map = (MapView)findViewById(R.id.map_view); map.getController().animateTo(new GeoPoint((int)(lat*1E6),//1000000), (int)(lon*1E6))); }//onLocationChanged @Override public void onProviderDisabled(String provider) { // TODO Auto-generated method stub Toast.makeText(this, "GPS disabled", Toast.LENGTH_SHORT).show(); }//onProviderDisabled @Override public void onProviderEnabled(String provider) { // TODO Auto-generated method stub Toast.makeText(this, "GPS enabled", Toast.LENGTH_SHORT).show(); }//onProviderEnabled @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub }//onStatusChanged }//class </code></pre> <p>the whole of my log cat when i run the app through my device (16/12/2011)</p> <pre><code>D/InputTransport(5357): Input channel constructed: name='40baf680 Toast (client)', ashmemFd=54, receivePipeFd=57, sendPipeFd=58 I/MapActivity(5357): Handling network change notification:CONNECTED E/MapActivity(5357): Couldn't get connection factory client I/ViewRoot(5357): !@FINISH DRAWING : sg.edu.tp/sg.edu.tp.SIP_TestMapActivity I/ViewRoot(5357): !@finishDrawing is completed : sg.edu.tp/sg.edu.tp.SIP_TestMapActivity I/ViewRoot(5357): !@FINISH DRAWING : Toast I/ViewRoot(5357): !@finishDrawing is completed : Toast D/InputTransport(5357): Input channel destroyed: name='40baf680 Toast (client)', ashmemFd=54, receivePipeFd=57, sendPipeFd=58 </code></pre> <p>manifest :</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="sg.edu.tp" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="10" /&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" &gt; &lt;activity android:label="@string/app_name" android:name=".SIP_MLT_TestActivity" &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=".SIP_TestMapActivity"&gt;&lt;/activity&gt; &lt;activity android:name=".SIP_TestDraw1Activity"&gt;&lt;/activity&gt; &lt;activity android:name=".SIP_TestDraw2Activity"&gt;&lt;/activity&gt; &lt;/application&gt; &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt; &lt;/manifest&gt; </code></pre>
    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