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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:07:48+00:00 2026-06-01T13:07:48+00:00

I’m developing an Android app that uses Osmdroid to display the maps in offline

  • 0

I’m developing an Android app that uses Osmdroid to display the maps in offline mode. I have an issue when I want to zoom in or out by pinching on the map or using the build-in zoomcontrols. When I zoom in the map tiles are not always correctly rendered and when I zoom out the sometimes there are some gray tiles in the map, sometimes everything is rendered OK. It’s not related on the location displayed on the map. My map tiles are stored in an osmdroid zip-file with the Mapnik source in the folder /mnt/sdcard/osmdroid. I’m using osmdroid-3.0.7.

So, any help is welcome.

See my code below (my includes aren’t included here in the code):

public class MapActivity extends OSMapActivity {

private ArrayList<String[]> mapPointData;
private ArrayList<String[]> multiData;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.setContentView(R.layout.map);

    setABTitle(getIntent().getExtras().getStringArray("geoLoc")[0]);
    actionButtonVisible(getIntent().getExtras().getBoolean("routeList"));

    initLayout();
    setHomePoint();
}

@Override
protected void onResume() {
    super.onResume();
    Prefs.clearMapPrefs(this);
}

private void initLayout() {

    c = this;
    // Buttons @ top of the activity
    doseeBN = (ImageView) findViewById(R.id.mapDoseeBN);
    eatdrinkBN = (ImageView) findViewById(R.id.mapEatdrinkBN);
    nightlifeBN = (ImageView) findViewById(R.id.mapNightlifeBN);
    sleepBN = (ImageView) findViewById(R.id.mapSleepBN);

    // The LinearLayout with the ScrollView for the Subcategories in "Do & See"
    doseeLL = (LinearLayout) findViewById(R.id.doseeSubCatLL);
    top10BN = (Button) findViewById(R.id.mapDoseeTop10BN);
    monumentsBN = (Button) findViewById(R.id.mapDoseeMonumentsBN);
    museumBN = (Button) findViewById(R.id.mapDoseeMuseumsBN);
    cultureBN = (Button) findViewById(R.id.mapDoseeCultureBN);
    attractionsBN = (Button) findViewById(R.id.mapDoseeAttractionBN);
    shoppingBN = (Button) findViewById(R.id.mapDoseeShoppingBN);
    marketBN = (Button) findViewById(R.id.mapDoseeMarketBN);

    // Init of the map an mapcontroller
    mapView = (MapView) findViewById(R.id.osmMV);
    mapView.setTileSource(TileSourceFactory.MAPNIK);
    mapController = mapView.getController();
    mapController.setZoom(16);
    mapView.setUseDataConnection(false);

    mapView.setBuiltInZoomControls(true);
    mapView.setMultiTouchControls(true);
   // mapView.setDrawingCacheEnabled(true);


    mapData = new ArrayList<String[]>();
    mapPointData = new ArrayList<String[]>();
    multiData = new ArrayList<String[]>();
}

private void setHomePoint() {
    //GeoPoint centerPt = new GeoPoint(50.89489, 4.34140); // Point of Grand Place Brussels

    homeLat = Double.parseDouble(getIntent().getExtras().getStringArray("geoLoc")[1]);
    homeLong = Double.parseDouble(getIntent().getExtras().getStringArray("geoLoc")[2]);

    GeoPoint centerPt = new GeoPoint(homeLat, homeLong);

    if (checkMapRange(Double.parseDouble(getIntent().getExtras().getStringArray("geoLoc")[1]), 
            Double.parseDouble(getIntent().getExtras().getStringArray("geoLoc")[2]))) {
        mapController.setCenter(centerPt);

        Drawable marker = getResources().getDrawable(R.drawable.ic_pin_marker);

        ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
        items.add(new OverlayItem("Here I am!", "Hello", centerPt));
        ItemizedOverlay<OverlayItem> itemOverlay = 
                                new ItemizedIconOverlay<OverlayItem>(items, marker, null, new DefaultResourceProxyImpl(this));
        mapView.getOverlays().add(itemOverlay);
        mapView.invalidate();
    } else {
        mapController.setCenter(new GeoPoint(50.89489, 4.34140));
        mapController.setZoom(11);
        Action.alert(this, getResources().getString(R.string.alert_title_notinregion), 
                getResources().getString(R.string.alert_message_notinregion), false);
        mapView.setClickable(false);
    }
}

public void onClickMapPointsBN(View v) {

    switch(v.getId()) {
    case R.id.mapDoseeBN:
        setPrefsCategory("DOSEE", doseeBN, "btn_map_dosee", "btn_map_dosee_pressed");
        break;
    case R.id.mapEatdrinkBN:
        setPrefsCategory("EATDRINK", eatdrinkBN, "btn_map_eatdrink", "btn_map_eatdrink_pressed");
        break;
    case R.id.mapNightlifeBN:
        setPrefsCategory("NIGHTLIFE", nightlifeBN, "btn_map_nightlife", "btn_map_nightlife_pressed");
        break;
    case R.id.mapSleepBN:
        setPrefsCategory("SLEEP", sleepBN, "btn_map_sleep", "btn_map_sleep_pressed");
        break;
    }

    setPOIs();
}

public void onClickDoseeListBN(View v) {
    switch (v.getId()) {
    case R.id.mapDoseeTop10BN:
        setDosseSubCat(Definitions.doseeList[0], top10BN);
        break;
    case R.id.mapDoseeMuseumsBN:
        setDosseSubCat(Definitions.doseeList[2], museumBN);
        break;
    case R.id.mapDoseeCultureBN:
        setDosseSubCat(Definitions.doseeList[3], cultureBN);
        break;
    case R.id.mapDoseeAttractionBN:
        setDosseSubCat(Definitions.doseeList[4], attractionsBN);
        break;
    case R.id.mapDoseeShoppingBN:
        setDosseSubCat(Definitions.doseeList[5], shoppingBN);
        break;
    case R.id.mapDoseeMarketBN:
        setDosseSubCat(Definitions.doseeList[6], marketBN);
        break;
    default:
        setDosseSubCat(Definitions.doseeList[1], monumentsBN);
        break;
    }

    setPOIs();
}

private void setPrefsCategory(String cat, ImageView btn, String image, String imageSelected) {
    boolean sel = Prefs.getBoolean(this, "map" + cat, false);

    Prefs.setBoolean(this, "map" + cat, !sel);
    setCategoryImage(btn, image, imageSelected, sel);

    if (cat.equalsIgnoreCase("DOSEE")) {
        if (sel) {
            doseeLL.setVisibility(View.GONE);
        } else {
            doseeLL.setVisibility(View.VISIBLE);

            for (String s : Definitions.doseeList) {
                if (s.equals(Definitions.doseeList[1])) {
                    Prefs.setBoolean(this, "mapDS_" + s, true);
                } else {
                    Prefs.setBoolean(this, "mapDS_" + s, false);
                }
            }
        }

        setSubcategoryColor(sel);
    }
}

private void setCategoryImage(ImageView btn, String image, String imageSelected, boolean selected) {
    String devLang = Prefs.getString(this, "devLanguage", "en");

    if (!devLang.equalsIgnoreCase("en")) {
        image += "_" + devLang;
        imageSelected += "_" + devLang;
    }

    if (selected) {
        btn.setImageResource(this.getResources().getIdentifier(image, "drawable", getPackageName()));
    } else {
        btn.setImageResource(this.getResources().getIdentifier(imageSelected, "drawable", getPackageName()));
    }
}

private void setSubcategoryColor(boolean doseeSelected) {
    setDoseeSubCatTextColor(true, top10BN);
    setDoseeSubCatTextColor(doseeSelected, monumentsBN);
    setDoseeSubCatTextColor(true, museumBN);
    setDoseeSubCatTextColor(true, cultureBN);
    setDoseeSubCatTextColor(true, attractionsBN);
    setDoseeSubCatTextColor(true, shoppingBN);
    setDoseeSubCatTextColor(true, marketBN);
}

private void setPOIs() {
    mapView.getOverlays().clear();
    mapView.invalidate();
    mapData.clear();

    setHomePoint();

    boolean selected;

    for (String category : Definitions.categoryList) {
        selected = Prefs.getBoolean(this, "map" + category, false);

        Log.d("VB.Map", "Category: " + category + " selected: " + selected);
        if (selected) {
            if (category.equalsIgnoreCase("DOSEE")) {
                boolean subSelected;

                for (String subcategory : Definitions.doseeList) {
                    subSelected = Prefs.getBoolean(this, "mapDS_" + subcategory, false);

                    if (subSelected) {
                        getSqlData(category, subcategory);
                    }
                }
            } else {
                getSqlData(category, null);
            }
        }
    }

    removeMapDataItems();
    //mapPointData = mapData;
    //multiDataLocationSelector();
    setMapDataPoints();
    //setMultiMapPoints();
}

private void getSqlData(String category, String subCategory) {
    ArrayList<String[]> sqlData = SqlDB.db.getCategoryItems(Adjust.rewriteCategoryName(category), subCategory);

    for (String[] data : sqlData) {
        mapData.add(data);
    }
}

private void removeMapDataItems() {
    for (int i = 0; i < mapData.size(); i++) {
        if ((mapData.get(i)[13].equalsIgnoreCase("")) || (mapData.get(i)[14].equalsIgnoreCase(""))) {
            mapData.remove(i);
            i--;
        }
    }
}

private void setDosseSubCat(String subCat, Button btn) {
    boolean selected = Prefs.getBoolean(this, "mapDS_" + subCat, false);

    Prefs.setBoolean(this, "mapDS_" + subCat, !selected);

    setDoseeSubCatTextColor(selected, btn);
}

private void setDoseeSubCatTextColor(boolean selected, Button btn) {
    if (selected) {
        btn.setTextColor(Definitions.colorDoseeSubcat);
    } else {
        btn.setTextColor(Definitions.colorDoseeSubcatSelected);
    }
}

private void setMapDataPoints() {
    if (mapData != null) {
        ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
        OverlayItem overlayItem;

        for (String[] item : mapData) {
            multiData.add(item);
            if (existsInOverlayItems(item, mapOverlays)) {
                overlayItem = new OverlayItem("-1", "", new GeoPoint(Float.parseFloat(item[13]), Float.parseFloat(item[14])));
                overlayItem.setMarker(getResources().getDrawable(R.drawable.ic_pin_multiple));
            } else {
                overlayItem = new OverlayItem(item[0], "", new GeoPoint(Float.parseFloat(item[13]), Float.parseFloat(item[14])));
                overlayItem.setMarker(getResources().getDrawable(getResources().getIdentifier(item[15], "drawable", getPackageName())));
            }

            mapOverlays.add(overlayItem);
        }

        setMapOverlays(mapOverlays);
    }
}

private boolean existsInOverlayItems(String[] item, ArrayList<OverlayItem> overlayItemList) {
    for (int i = 0; i < overlayItemList.size(); i++) {
        if ((new GeoPoint(Double.parseDouble(item[13]), Double.parseDouble(item[14]))).equals(overlayItemList.get(i).mGeoPoint)) {
            overlayItemList.remove(i);
            return true;
        }
    }

    return false;
}

private void setMapOverlays(ArrayList<OverlayItem> overlays) {  
    ItemizedOverlay<OverlayItem> itemOverlays = new ItemizedIconOverlay<OverlayItem>(
            overlays, getResources().getDrawable(R.drawable.ic_pin_marker), new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {

        public boolean onItemLongPress(int arg0, OverlayItem item) {
            mapOverlayItemPressed(Integer.parseInt(item.mTitle), item);
            return false;
        }

        public boolean onItemSingleTapUp(int arg0, OverlayItem item) {
            mapOverlayItemPressed(Integer.parseInt(item.mTitle), item);
            return false;
        }
    }, new DefaultResourceProxyImpl(this));


    mapView.getOverlays().add(itemOverlays);

    mapView.invalidate();
}

private void mapOverlayItemPressed(int itemId, OverlayItem overlayItem) {
    if (itemId == -1) {
        Collect.multiPOIList.clear();

        for (String[] item : multiData) {
            if ((new GeoPoint(Double.parseDouble(item[13]), Double.parseDouble(item[14]))).equals(overlayItem.mGeoPoint)) {
                Collect.multiPOIList.add(item);
            }
        }

        Action.alertWithListView(this, getResources().getString(R.string.alert_title_multiplepoi), false);

    } else {
        SqlDB.db.getItemsById(itemId);

        Bundle b = new Bundle();
        b.putInt("listSelection", 0);

        Action.newIntent(c, DetailActivity.class, b);
    }
}

private boolean checkMapRange(double lat, double lng) {
    double mapLatMax = 50.922085;
    double mapLatMin = 50.781631;
    double mapLongMin = 4.240723;
    double mapLongMax = 4.490662;

    if ((lat > mapLatMin) && (lat < mapLatMax)) {
        if ((lng > mapLongMin) && (lng < mapLongMax)) {
            return true;
        }
    }
    return false;
}

}

And here the code of the OSMapActivity:

public class OSMapActivity extends ActionbarActivity {

protected Context c;

protected MapView mapView;
protected MapController mapController;
protected ArrayList<String[]> mapData;

protected ImageView doseeBN;
protected ImageView eatdrinkBN;
protected ImageView nightlifeBN;
protected ImageView sleepBN;
protected LinearLayout doseeLL;

protected Button top10BN;
protected Button monumentsBN;
protected Button museumBN;
protected Button cultureBN;
protected Button attractionsBN;
protected Button shoppingBN;
protected Button marketBN;

protected double homeLat;
protected double homeLong;

public void onClickABActionButton(View v) {
    boolean actionButton = Prefs.getBoolean(this, "abActionButtonRoute", false);

    if (actionButton) {
        // TODO Add with current location => location manager in separate class
        /*GPS.init(this);
        GPS.enableGPSProvider();
        GPS.enableNetworkProvider();
        //Action.loadApp(this, Intent.ACTION_VIEW, Uri.parse("geo:50.89489,4.34140?daddr=Heiveld+21+Opwijk"));
        Action.loadApp(this, Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr=" + GPS.latitude + "," + GPS.longitude
                                                            + "&daddr=Heiveld+21+1745+Opwijk"));
        GPS.stop();*/
        Action.loadMapsWithMyLocation(this, homeLat, homeLong);
    } else {
        Collect.dbList.clear();

        for (String[] data : mapData) {
            Collect.dbList.add(data);
        }

        // TODO Load new intent with list
        Action.newIntent(this, MapListActivity.class, null);

    }
}

}

Thanks for your help.

Kr

  • 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-01T13:07:49+00:00Added an answer on June 1, 2026 at 1:07 pm

    I raised an issue on version 3.0.6 about this. In the comments the authors say it was fixed on Feb 1st. As the 3.0.7 jar is dated Jan 29, I assume the fix isn’t in it. I’m sticking with version 3.0.5 for now, although the cycle maps don’t work in it and the tile loading can be a bit flickery. If your maps are offline though, they should load pretty fast and flicker might not be an issue.

    • 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 have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't

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.