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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:42:44+00:00 2026-05-22T23:42:44+00:00

Hey. I am having trouble setting up the OSMdroid library to display OpenSourceMaps. I

  • 0

Hey. I am having trouble setting up the OSMdroid library to display OpenSourceMaps. I am working on an activity that will allow the user to see a map of their current location wit buttons to allow the user to switch between normal google maps view, terrain google maps view, and openstreetmaps view. I am currently using the JAR file and just adding it to the build path of my project. It compiles fine however I don’t understand how to use the library. There are very few tutorials/directions online. Do I need to make an IMapView tag in the layout and use it like a Google Map view? How do I switch the layout tiles from normal google maps view?

If someone could just give me a very short walkthrough of how this library works it would be much appreciated. I have been coding in JAVA for numerous years so I just need an english description of what I need to do.

Thanks in advance.

  • 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-22T23:42:45+00:00Added an answer on May 22, 2026 at 11:42 pm

    I managed to get osmdroid working in a project, but had to have the Google and the OSM views in different activities as if you switch a Mapview from Google to OSM and then try to go back to Google, I got a runtime error saying something like “only one mapview allowed per activity”. This results in a lot of duplicate code but it does run OK.

    Use the latest osmdroid-android-3.0.3.jar, it’s much simpler for drawing overlays. You’ll also need to include slf4j-android-1.5.8.jar. For what it’s worth here is the code for the lashed up demo that used to start with. It’s got a location listener and draws a very simple overlay (line across the screen) If you are familiar with Google Maps, you should be able to adapt it for your purpose.

    package osmdemo.demo;
    
    import java.util.List;
    
    import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
    import org.osmdroid.util.GeoPoint;
    import org.osmdroid.views.MapController;
    import org.osmdroid.views.MapView;
    import org.osmdroid.views.MapView.Projection;
    import org.osmdroid.views.overlay.Overlay;
    import org.osmdroid.views.util.constants.MapViewConstants;
    
    import android.app.Activity;
    import android.content.Context;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.graphics.Rect;
    import android.graphics.Paint.Style;
    import android.location.Location;
    import android.location.LocationListener;
    import android.location.LocationManager;
    import android.os.Bundle;
    
    public class DemoMap extends Activity implements LocationListener,
            MapViewConstants {
    
        private MapView mapView;
        private MapController mapController;
        private MapOverlay mmapOverlay = null;
        private LocationManager mLocMgr;
    
        /** 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(15);
            GeoPoint point2 = new GeoPoint(53554070, -2959520);
            mapController.setCenter(point2);
            mLocMgr = (LocationManager) getSystemService(LOCATION_SERVICE);
            mLocMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 100,
                    this);
            this.mmapOverlay = new MapOverlay(this);
            List<Overlay> listOfOverlays = mapView.getOverlays();
            listOfOverlays.add(mmapOverlay);
            mapView.invalidate();
        }
    
        public void onLocationChanged(Location location) {
    
            int lat = (int) (location.getLatitude() * 1E6);
            int lng = (int) (location.getLongitude() * 1E6);
            GeoPoint gpt = new GeoPoint(lat, lng);
            mapController.setCenter(gpt);
            mapView.invalidate();
        }
    
        public class MapOverlay extends org.osmdroid.views.overlay.Overlay {
    
            public MapOverlay(Context ctx) {
                super(ctx);
                // TODO Auto-generated constructor stub
            }
    
            @Override
            protected void draw(Canvas pC, MapView pOsmv, boolean shadow) {
                if (shadow)
                    return;
    
                Paint lp3;
                lp3 = new Paint();
                lp3.setColor(Color.RED);
                lp3.setAntiAlias(true);
                lp3.setStyle(Style.STROKE);
                lp3.setStrokeWidth(1);
                lp3.setTextAlign(Paint.Align.LEFT);
                lp3.setTextSize(12);
                final Rect viewportRect = new Rect();
                final Projection projection = pOsmv.getProjection();
                viewportRect.set(projection.getScreenRect());
                // Draw a line from one corner to the other
                pC.drawLine(viewportRect.left, viewportRect.top,
                        viewportRect.right, viewportRect.bottom, lp3);
            }
    
        }
    
        @Override
        public void onProviderDisabled(String arg0) {}
    
        @Override
        public void onProviderEnabled(String provider) {}
    
        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {}
    
    }
    

    And the xml (copymain.xml)

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <org.osmdroid.views.MapView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent"
            android:id="@+id/mapview"
            ></org.osmdroid.views.MapView>
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey smarties. I'm having trouble with the following SQL statement. I know that I
Hey guys, I'm having trouble trying to find the user's longitude and location as
Hey guys - I am having trouble setting up my Django urls file correctly
Hey all, I'm having some trouble setting up my grails application. Running the app
Hey I'm having a little trouble. I've been working with xna for a while,
Hey having some trouble trying to maintain transparency on a png when i create
Hey guys i want to execute my SQL statement but im having synatx trouble,
Hey all! Having a little trouble with my stack. Im trying to print each
Hey, I'm having an issue that appears to be related to collation, but I'm
hey people im having trouble with loading my array of strings into a tableview

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.