如何显示整个世界并在上面加上标记? [英] How to show entire world and put markers on it?

查看:154
本文介绍了如何显示整个世界并在上面加上标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想展示整个世界的流行地图,并在上面标记.

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

我尝试为此使用Google Maps,但似乎( 此处 )不支持缩小到无法显示整个世界.

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

在Wikipedia( 此处 )的中心,地球在 30°00′N 31°00′E 上,但这似乎在埃及,即使在Wikipedia页面本身上,它也不像世界地图的中心:

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:

我也在 此处 找到了类似的问题,因此我将其转换为到Android代码:

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:

我还尝试使用缩放功能(看起来 此处 ),但它永远不会缩小到无法显示出像大洲一样大的地方:

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));

我选择"1",因为文档说"1"是"world"的值:

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:世界

问题

如何在Google地图上显示整个世界?

The question

How can I show the entire world on Google Maps ?

或者,仅显示世界地图(静态图像也很好),并能够在其上放置标记,还有什么好选择吗?甚至可以使用VectorDrawable吗?

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?

推荐答案

使用MapView(或MapFragment)

...如果需要显示 整个视口中,最好使用精简模式

... 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.

所以,像MainActivity一样:

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);
        }
    }
}

activity_main.xml(也可以通过

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"
    />

你有类似的东西:

这篇关于如何显示整个世界并在上面加上标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆