question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

osmdroid osm looks more "zoom out" than Google Maps v2 with the same zoom level

See original GitHub issue

Issue Type

[X] Question

Description and/or steps/code to reproduce the problem

I am trying migrate my project from Google Maps v2 to osmdroid, I knew osmdroid is a replacement of v1. And my goal is to reuse the same map config, e.g. zoom level, when replacing Google Maps v2 by osmdroid.

My question is that, in my testing, the zoom level of Google Maps v2 and osmdroid is the same, let’s say zoom level = 13, the Google Maps always look like more “zoom in” than osm in osmdroid, and I don’t know why.

I don’t know too much about coordinate system, I thought both OSM and Google Maps use WGS84, then the zoom level config should be the same or very similar. Is it intended or something I missed? What should I do to reuse the same zoom level from Google Maps v2 to osmdroid?

The maps, both are in zoom level 13.

MapTestActivity.java

public class MapTestActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle("Map Test");
        setContentView(R.layout.map_layout);

        // Google Maps v2
        SupportMapFragment supportMapFragment = SupportMapFragment.newInstance();
        getSupportFragmentManager().beginTransaction().add(R.id.container, supportMapFragment).commit();

        supportMapFragment.getMapAsync(googleMap -> {
            googleMap.setMaxZoomPreference(13f);
            googleMap.setMinZoomPreference(9f);
            googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40.730610, -73.935242), 10f));
            googleMap.addMarker(new MarkerOptions()
                    .position(new LatLng(40.730610, -73.935242)));
        });

        // osmdroid
        MapView mapView = findViewById(R.id.map_view);

        Context ctx = getApplicationContext();
        Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));

        mapView.setTileSource(TileSourceFactory.MAPNIK);
        mapView.setMultiTouchControls(true);

        mapView.getController().setZoom(10d);
        mapView.setMaxZoomLevel(13d);
        mapView.setMinZoomLevel(9d);
        mapView.setExpectedCenter(new GeoPoint(40.730610, -73.935242));

        Marker marker = new Marker(mapView);
        marker.setPosition(new GeoPoint(40.730610, -73.935242));
        mapView.getOverlays().add(marker);

        CopyrightOverlay copyrightOverlay = new CopyrightOverlay(ctx);
        mapView.getOverlays().add(copyrightOverlay);
    }
}

map_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <org.osmdroid.views.MapView
        android:id="@+id/map_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
</LinearLayout>

Environment

All

Version of osmdroid the issue relates to:

6.1.14

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
monsieurtanukicommented, Sep 12, 2022

Indeed true should be the default. Is that a breaking change? How smoothly can we do that? Well, just editing private boolean mTilesScaledToDpi = false; and adding an explicit release note would do the trick I guess.

0reactions
MKergallcommented, Sep 12, 2022

BTW, most devices now have high density, requiring this setting => I think we should set this tilesScaledToDpi setting to true by default.

@monsieurtanuki @spyhunter99 your view?

Read more comments on GitHub >

github_iconTop Results From Across the Web

why osmdroid loaded a lot of maps. & Zoom to a wrong place
The map is loaded. However, when I zoom out I found that there are more than one maps loaded.. in fact, there seems...
Read more >
Markers moving when zooming (Android 28) #1349 - GitHub
The markers move from their location as the map is zoomed in or out. This happens with both a custom and the default...
Read more >
osmdroid
What map projection does osmdroid use and or support? There are tons of map ... In this case, X and Y are the...
Read more >
Controlling Zoom and Pan | Maps JavaScript API
The map below uses the gestureHandling option set to cooperative , allowing the user to scroll the page normally, without zooming or panning...
Read more >
How to "calculate" distance-to-ground of all 18 OSM zoom ...
Now assume further that we want to texture the "visible" fragments of the "ground" plane with OSM and/or Bing/MapQuest/Google aerial map tiles, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found