Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6061643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:57:38+00:00 2026-05-23T08:57:38+00:00

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;

  • 0
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 */

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?

My AndroidManifest.xml is giving all required permissions I think

<?xml version="1.0" encoding="utf-8"?>

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".gpstestActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>  
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:57:38+00:00Added an answer on May 23, 2026 at 8:57 am

    In your setMap(), you never set

    myMap = map;

    So in initMyLocation, you are passing null for the pMapView parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

package com.crumbin.tabs; //java package import java.io.IOException; import java.util.ArrayList; import org.json.JSONException; import android.app.Activity; import android.app.AlertDialog;
package com.crumbin.tabs; import java.util.ArrayList; import java.util.HashMap; import org.apache.http.client.HttpClient; import android.content.Context; import android.database.Cursor; import android.location.Location;
package net.learn2develop.PopularAttractions; import java.io.IOException; import java.util.List; import java.util.Locale; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController;
package com.example.application; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import org.jsoup.Jsoup; import org.jsoup.nodes.Document;
package com.org.myOxygen.activities; import java.util.Stack; import android.app.Activity; import android.app.ActivityGroup; import android.app.LocalActivityManager; import android.content.Intent; import android.os.Bundle;
package com.example.android.home; import android.app.Activity; import android.os.Bundle; import android.widget.*; import android.view.*; public class HomeActivity extends
package vaannila; import java.util.ArrayList; import com.opensymphony.xwork2.ActionSupport; public class RegisterAction extends ActionSupport { private String
package com.example.helloandroid; import android.app.Activity; import android.os.Bundle; import android.widget.Button; import android.view.View; import android.view.View.OnClickListener; //Create an
package org.apache.wicket.examples.guestbook; import java.util.Date; import org.apache.wicket.IClusterable; public class Comment implements IClusterable { private String
package com.owen.quartergames.dao; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.