Note that there are some explanatory texts on larger screens.

plurals
  1. POOsmdroid Overlays crash application (Android)
    primarykey
    data
    text
    <pre><code>package gpstest.example.com; import org.osmdroid.tileprovider.tilesource.TileSourceFactory; import org.osmdroid.views.overlay.MyLocationOverlay; import org.osmdroid.util.GeoPoint; import org.osmdroid.views.MapView; import android.content.Context; import android.graphics.Paint; import android.app.Activity; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.widget.Toast; public class gpstestActivity extends Activity { public LocationManager mlocManager; public LocationListener mlocListener; public boolean isFirstRun=true; protected final Paint mPaint = new Paint(); private MapView myMap; private MyLocationOverlay myLocOverlay; /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); gpsEnable(); setMap(); initMyLocation(); } public void setMap(){ MapView map = (MapView) findViewById(R.id.map); map.setTileSource(TileSourceFactory.MAPNIK); map.setBuiltInZoomControls(true); map.setMultiTouchControls(true); map.getController().setZoom(16); map.getController().setCenter(new GeoPoint(30266000, -97739000)); } private void initMyLocation() { myLocOverlay = new MyLocationOverlay(this, myMap); myLocOverlay.enableMyLocation(); myMap.getOverlays().add(myLocOverlay); } public void gpsEnable (){ mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); mlocListener = new MyLocationListener(); mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 10, 50, mlocListener); } public void gpsDisable(){ mlocManager.removeUpdates(mlocListener);} /* Class My Location Listener */ public class MyLocationListener implements LocationListener { @Override public void onLocationChanged(Location loc) { loc.getLatitude(); loc.getLongitude(); double longi=loc.getLongitude(); double lati=loc.getLatitude(); MapView map = (MapView) findViewById(R.id.map); map.getController().setCenter(new GeoPoint(lati, longi)); String Text="My current location is: " + "Latitud = " + loc.getLatitude() + "Longitud = " + loc.getLongitude(); Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_SHORT).show(); //initMyLocation(); } @Override public void onProviderDisabled(String provider) { Toast.makeText( getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT ).show(); mlocManager.removeUpdates(mlocListener); } @Override public void onProviderEnabled(String provider) { Toast.makeText( getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show(); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { Toast.makeText( getApplicationContext(), "Status changed", Toast.LENGTH_SHORT).show(); } }/* End of Class MyLocationListener */ @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.beenden: mlocManager.removeUpdates(mlocListener);} return true; } protected void onPause(){ Toast.makeText( getApplicationContext(), "On Pause", Toast.LENGTH_SHORT).show(); gpsDisable(); isFirstRun=false; super.onPause(); } protected void onDestroy(){ Toast.makeText( getApplicationContext(), "Destroyed", Toast.LENGTH_SHORT).show(); gpsDisable(); super.onDestroy(); } protected void onResume(){ if (isFirstRun==false){gpsEnable();} Toast.makeText( getApplicationContext(), "Resumed", Toast.LENGTH_SHORT).show(); super.onResume(); } }/* Ende Activity */ </code></pre> <p>Whenever I call initMyLocation, the app crashes (bot on emulator and device). Same happens when I try to implement a MiniMap. I do exactly the same as in the SampleExtensive example from the Osmdroid repository. What am I doing wrong?</p> <p>My AndroidManifest.xml is giving all required permissions I think</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; </code></pre> <p> </p> <pre><code>&lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;activity android:name=".gpstestActivity" android:label="@string/app_name"&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;/application&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.INTERNET"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt; &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt; &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt; </code></pre> <p></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.
    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