3

Background

I want to show the popular map of the entire world, and put markers on it.

The problem

I tried to use Google Maps for it, but it seems (here) it doesn't support zooming out enough to show the entire world.

What I've found

Looking on Wikipedia (here), the center of the earth is on 30°00′N 31°00′E , but this seems to be in Egypt, and it doesn't look like the center of the world map, even on the Wikipedia page itself:

enter image description here

I've also found a similar question here, so I've converted it to Android code:

    MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.mapFragment);
    mapFragment.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(final GoogleMap googleMap) {
            LatLngBounds allowedBounds = new LatLngBounds(
                    new LatLng(-85, 180),    // bottom right corner
                    new LatLng(85, -180)    // top left corner of map
            );
            double k = 5.0f;
            double n = allowedBounds.northeast.latitude - k;
            double e = allowedBounds.northeast.longitude - k;
            double s = allowedBounds.southwest.latitude + k;
            double w = allowedBounds.southwest.longitude + k;
            LatLng neNew = new LatLng(n, e);
            LatLng swNew = new LatLng(s, w);
            LatLngBounds boundsNew = new LatLngBounds(swNew, neNew);
            googleMap.setLatLngBoundsForCameraTarget(boundsNew);
        }
    });

But it does't show entire world at all:

enter image description here

I've also tried to play with the zoom (looking here), but it never zoomed out enough to show as much as continents:

googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(30, 31), 1));

enter image description here

I chose "1", because the docs say that "1" is the value for "world":

The following list shows the approximate level of detail you can expect to see at each zoom level:

1: World

The question

How can I show the entire world on Google Maps ?

Or, is there any good alternative to just show the world map (static image is good too), and be able to put markers on it? Maybe even using a VectorDrawable?

Is there an image I can show, and somehow put markers on it?

Community
  • 1
  • 1
android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • did you found any solution? – yosriz Mar 06 '17 at 14:26
  • @yosriz No, but what we did for now, that works in our case alone (it's just a POC anyway), is to put the map as image in ImageVIew, within a FrameLayout, set the scaleType to be from start (top left corner will be the same for both the content and the view), set I'mageView's height to be match_parent and width as wrap_content, and put the on-top views in relation to the ImageView's size, because the content of the ImageView should fit the same size that it got to be. Again, this is a very specific case, so it's not a nice solution at all. – android developer Mar 06 '17 at 15:41
  • So you basically create custom view with overlay view for each country? Did you consider using Google GeoChart? – yosriz Mar 06 '17 at 18:02
  • Hello anyone found this proper solution? i used liteMode in mapview but its not showing world map. – khushbu May 10 '19 at 09:21

3 Answers3

1

Its possible to show entire World and put markers on it with MapView (or MapFragment) Lite Mode:

... If you need to show the entire world in the viewport, it may be better to use Lite Mode.

Markers is in "Partly" Supported Features:

You can add a marker and respond to a click event. You can also add custom marker icons. It's not possible to make a marker draggable. Markers on a lite mode map are flat, and they cannot be rotated.

Also, you can use other features like lines and polygon drawing, etc.

So, with MainActivity like:

public class MainActivity extends AppCompatActivity {

    private static final String MAP_VIEW_BUNDLE_KEY = "MapViewBundleKey";

    private MapView mMapView;
    private GoogleMap mGoogleMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Bundle mapViewBundle = null;
        if (savedInstanceState != null) {
            mapViewBundle = savedInstanceState.getBundle(MAP_VIEW_BUNDLE_KEY);
        }

        mMapView = (MapView) findViewById(R.id.mapview);
        mMapView.onCreate(mapViewBundle);

        mMapView.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(GoogleMap googleMap) {
                mGoogleMap = googleMap;
                mGoogleMap.addMarker(new MarkerOptions()
                        .position(new LatLng(31.755983, 35.212879))
                        .title("Jerusalem"));
            }
        });
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);

        Bundle mapViewBundle = outState.getBundle(MAP_VIEW_BUNDLE_KEY);
        if (mapViewBundle == null) {
            mapViewBundle = new Bundle();
            outState.putBundle(MAP_VIEW_BUNDLE_KEY, mapViewBundle);
        }
    }
}

and activity_main.xml (also its possible to set Lite Mode for MapView programmatically via GoogleMapOptions.liteMode(true)):

<com.google.android.gms.maps.MapView android:id="@+id/mapview"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    map:cameraZoom="1"
    map:mapType="normal"
    map:liteMode="true"
    />

you got something like that:

Google Maps Whole World

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
  • This looks promising! Sadly I've moved forward from this question a long time ago. Can you please put a Github sample for this, so that I could quickly check it out (sadly I don't have much time recent) ? For now, I will give you +1 for the effort. If the sample works, I will accept the answer. – android developer Oct 09 '18 at 11:44
  • @androiddeveloper Thanks! I can do it in a couple of days, but actually, all source code is in answer text. You can just create empty activity project, configure int for google maps and replace text of `MainActivity.java` and `activity_main.xml` by text from the answer. It really works. – Andrii Omelchenko Oct 09 '18 at 13:53
  • Please do. I will appreciate it. – android developer Oct 10 '18 at 07:09
  • I used liteMode in MapView but didn't get this type of output. I also need to show world map . – khushbu May 10 '19 at 09:22
0

You may be able to see the whole world using Lite Mode in the Google Maps Android API.

You can add markers on it the same as you would with the full map mode.

Lauren
  • 1
-1

This is a possible solution using Google Static Maps API.

The query is:

https://maps.googleapis.com/maps/api/staticmap?size=510x480&center=0,0&zoom=1&scale=2&key=YOUR_KEY

Just play around with the size parameters to test the desired view.

Static Map API

rags2riches-prog
  • 1,663
  • 1
  • 10
  • 22
  • Is this the API used on Android? Or do you show the one of the web? I know that for the web it's available, but not for Android (native functions). To me it seems what you show is for the web alone. – android developer Mar 09 '18 at 22:01
  • You said: _" is there any good alternative to just show the world map (static image is good too"_. I assumed you needed a static map to render in your app so you do not need this. Currently, there is no way you can zoom out a map and achieve a level 1 view because, even if you set your orientation to landscape to facilitate this, mobile view-ports are limited to a max level 3 or 4 zoom. – rags2riches-prog Mar 09 '18 at 22:30
  • You missed an important thing, which is the first sentence: "I want to show the popular map of the entire world, and put markers on it." . – android developer Mar 09 '18 at 23:59