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

  • Home
  • SEARCH
  • 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 8739807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:00:47+00:00 2026-06-13T11:00:47+00:00

I’m trying to make a custom marker for an OSMdroid map with a custom

  • 0

I’m trying to make a custom marker for an OSMdroid map with a custom Overlay class. I think I get it but it gives me a StackOverflowError on the draw contructor

Here’s the code of the main activity

package com.example.osmap1;import java.util.List;

import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.Overlay;

import com.example.osmap1.herramientas.MiOverlay;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {
MapView map;
MapController mc;
GeoPoint gp;
List<Overlay> mOverlays;

private static MainActivity mainActivity=null;
public static MainActivity getInstance(){
    if(mainActivity == null){
        mainActivity=new MainActivity();

    }
    return mainActivity;
}

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mainActivity=this;
    map=(MapView)findViewById(R.id.mapView);

    mc=map.getController();
    map.setBuiltInZoomControls(true);
    map.setMultiTouchControls(true);

    addPointToMapOverlay("43.528023","-5.672949");

}

private void addPointToMap (String latitud, String longitud){

    String coordenadas[]={latitud,longitud};
    double lat=Double.parseDouble(coordenadas[0]);
    double lng=Double.parseDouble(coordenadas[1]);
    GeoPoint gp=new GeoPoint((int)lat*1E6,(int)lng*1E6);
    mc.animateTo(gp);
    mc.setZoom(4);
    /*map.invalidate(); no funciona en osm*/
}

private void addPointToMapOverlay (String latitud, String longitud){


    String coordenadas[]={latitud,longitud};
    double lat=Double.parseDouble(coordenadas[0]);
    double lng=Double.parseDouble(coordenadas[1]);
    GeoPoint gp=new GeoPoint((int)lat*1E6,(int)lng*1E6);

    mOverlays=map.getOverlays();
    MiOverlay marker= new MiOverlay(gp);
    mOverlays.add(marker);
    mc.animateTo(gp);
    mc.setZoom(4);
    map.invalidate();
}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
 }
}

And this is my custom class code

public class MiOverlay extends Overlay{

private GeoPoint punto;


public MiOverlay(GeoPoint point) {

    super(MainActivity.getInstance().getBaseContext());
    this.punto=point;
    // TODO Auto-generated constructor stub
}

@Override
public void draw(Canvas canvas, MapView mapview, boolean shadow) {

    // TODO Auto-generated method stub
    this.draw(canvas, mapview, shadow);

    //se traduce el punto geo localizado a un punto en la pantalla
    Point scrnPoint = new Point();
    mapview.getProjection().toPixels(this.punto, scrnPoint);

    //se construye un bitmap a partir de la imagen
    Bitmap marker = BitmapFactory.decodeResource(MainActivity.getInstance().getResources(),com.example.osmap1.R.drawable.seas);

    //se dibuja la imagen del marker
    canvas.drawBitmap(marker, scrnPoint.x - marker.getWidth() / 2, scrnPoint.y - marker.getHeight() / 2, null);


}

public boolean onTouchEvent(MotionEvent event, MapView mapView) 
{   
    //---when user lifts his finger---
    if (event.getAction() == 1) {                
        GeoPoint p = (GeoPoint) mapView.getProjection().fromPixels(
            (int) event.getX(),
            (int) event.getY());
            Toast.makeText(MainActivity.getInstance().getBaseContext(), 
                p.getLatitudeE6() / 1E6 + "," + 
                p.getLongitudeE6() /1E6 , 
                Toast.LENGTH_SHORT).show();
    }                            
    return false;
}        

}

I think the problem coud be mapview.getProjection().toMapPixels(this.punto, scrnPoint) but I’m not sure… Any sugestion is wellcome

  • 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-13T11:00:48+00:00Added an answer on June 13, 2026 at 11:00 am

    It’s an infinite loop – I admit I don’t quite understand what you’re trying to do, but the draw function calls itself recursively:

    @Override
    public void draw(Canvas canvas, MapView mapview, boolean shadow) {
    
        this.draw(canvas, mapview, shadow); // This is the same method!
    }
    

    the result, illustrating flow of control, is this:

    draw()
     -> draw()
        -> draw()
        ...
        StackOverflowException
    

    perhaps you meant super.draw(canvas, mapview, shadow)?

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms

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.