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 7830375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:12:27+00:00 2026-06-02T11:12:27+00:00

I’m trying to create an application that uses OSMDroid and mapoverlays with geoPoints from

  • 0

I’m trying to create an application that uses OSMDroid and mapoverlays with geoPoints from the xml file, but i have a problem. Code editor doesn’t show me an error or warning but when i run the application in emulator it shows that application has stopped working.
This the code of mapActivity:

 public class MapsActivity extends Activity implements LocationListener, MapViewConstants {

    private MapView mapView;
    private MapController mapController;
    private LocationManager mLocMgr;
    static final String URL = "data/data/com.siroki.brijeg/data.xml";
    // XML node keys
    static final String KEY_ITEM = "object"; // parent node
    static final String KEY_ID = "id";
    static final String KEY_NAME = "name";
    static final String KEY_LON = "lon";
    static final String KEY_LAT = "lat";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.copymain);

        mapView = (MapView) this.findViewById(R.id.mapview);
        mapView.setTileSource(TileSourceFactory.MAPNIK);
        mapView.setBuiltInZoomControls(true);
        mapView.setMultiTouchControls(true);

        mapController = this.mapView.getController();
        mapController.setZoom(14);
        GeoPoint point2 = new GeoPoint(43.3803,  17.5981);
        mapController.setCenter(point2);
        mLocMgr = (LocationManager) getSystemService(LOCATION_SERVICE);
        mLocMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 100, this);

        mapView.invalidate();

        List<Overlay> mapOverlays = mapView.getOverlays();
        Drawable marker = this.getResources().getDrawable(R.drawable.ic_launcher);
        ObjectsOverlay itemizedOverlay = new ObjectsOverlay(marker, null);

        ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();

        XMLParser parser = new XMLParser();

        String xml = parser.getXmlFromUrl(URL); 
        Document doc = parser.getDomElement(xml); // getting DOM element

        NodeList nl = doc.getElementsByTagName(KEY_ITEM);



        // looping through all item nodes <item>
        for (int i = 0; i < nl.getLength(); i++) {
            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();
            Element e = (Element) nl.item(i);
            // adding each child node to HashMap key => value
            map.put(KEY_ID, parser.getValue(e, KEY_ID));
            map.put(KEY_NAME, parser.getValue(e, KEY_NAME));
            map.put(KEY_LON, "Rs." + parser.getValue(e, KEY_LON));
            map.put(KEY_LAT, parser.getValue(e, KEY_LAT));

            // adding HashList to ArrayList
            menuItems.add(map);
            GeoPoint geo = new GeoPoint(Double.parseDouble(parser.getValue(e, KEY_LAT)), Double.parseDouble(parser.getValue(e, KEY_LON)));
            OverlayItem overlayitem = new OverlayItem("Hellow", "World", geo);
            itemizedOverlay.addOverlay(overlayitem);
            mapOverlays.add(itemizedOverlay);

        }

    }

    public void onLocationChanged(Location location) {
        double lat = 43.3803;
        double lng = 17.5981 ;
        GeoPoint gpt = new GeoPoint(lat, lng);
        mapController.setCenter(gpt);
        mapView.invalidate();
    }

    @Override
    public void onProviderDisabled(String arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }



     }

ObjectsOverlay.java :

public class ObjectsOverlay extends ItemizedOverlay<OverlayItem> {



    public ObjectsOverlay(Drawable pDefaultMarker, ResourceProxy pResourceProxy) {
        super(pDefaultMarker, pResourceProxy);
        // TODO Auto-generated constructor stub
    }


    private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();

    private Context context;



    @Override
       protected OverlayItem createItem(int i) {
          return mapOverlays.get(i);
       }

       @Override
       public int size() {
          return mapOverlays.size();
       }

       protected boolean onTap(int index) {
          OverlayItem item = mapOverlays.get(index);
          AlertDialog.Builder dialog = new AlertDialog.Builder(context);
          dialog.setTitle(item.getTitle());
          dialog.setMessage(item.getSnippet());
          dialog.show();
          return true;
       }

       public void addOverlay(OverlayItem overlay) {
          mapOverlays.add(overlay);
           this.populate();
       }

    @Override
    public boolean onSnapToItem(int arg0, int arg1, Point arg2, IMapView arg3) {
        // TODO Auto-generated method stub
        return false;
    }

}

And XML file data.xml:

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

<objects>

    <object>
        <id>1</id>    

        <name>Siroki</name>

        <lon>17.602985</lon>

        <lat>43.374276</lat>
    </object> 
</objects>

I didn’t wrote the imports code becouse they take alot of space. 😀

  • 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-06-02T11:12:28+00:00Added an answer on June 2, 2026 at 11:12 am

    First, the context defined in your ObjectsOverlay is never being set. You should add a Context parameter in the constructor:

    public ObjectsOverlay(Drawable pDefaultMarker, ResourceProxy pResourceProxy, Context context) {
            super(pDefaultMarker, pResourceProxy);
            this.context = context;
        }
    

    so that the DialogBuilder used in onTap can have a context to create the dialog on. Without this your app will most probably crash when tapping an item.

    Next, you wrongly initialized the GeoPoint, it should be done like this:

    GeoPoint point = new GeoPoint(19240000,-99120000);
    OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
    

    GeoPoint coordinates are not double, like Location coordinates. They are int equal to coordinate * 1E6. Use it like this:

    int lon = (int)Math.round(lon_as_double*1E6)
    

    And the last thing, you do

    itemizedOverlay.addOverlay(overlayitem);
    mapOverlays.add(itemizedOverlay);
    

    in the same for-loop. But you should actually just addOverlay in the loop, where you add one by one object by its coordinates, and add the complete itemizedOverlay to the map after the loop.
    Oh and you could also add the overlay at the beginning (before the loop), and then populate it using addOverlay. The order does not matter, it only matters to add the overlay once with mapOverlays.add.

    Fix that and see if errors still happen.

    Regards.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from

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.