gpt4 book ai didi

android - 如何显示整个世界并在其上放置标记?

转载 作者:行者123 更新时间:2023-12-02 04:36:20 25 4
gpt4 key购买 nike

背景

我想显示整个世界的流行 map ,并在上面做标记。

问题

我尝试使用谷歌地图,但它似乎 ( here ) 不支持缩小到足以显示整个世界。

我发现了什么

看维基百科(here),地心在30°00′N 31°00′E,但是这里好像是在埃及,其实不是看起来像世界地图的中心,甚至在维基百科页面本身也是如此:

enter image description here

我也发现了一个类似的问题here ,所以我将其转换为 Android 代码:

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

但它根本没有显示整个世界:

enter image description here

我也尝试过缩放(看起来 here ),但它从来没有缩小到足以显示大洲:

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

enter image description here

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

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

1: World

问题

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

或者,是否有任何好的替代方法可以只显示世界地图(静态图像也不错),并能够在上面放置标记?甚至可以使用 VectorDrawable?

有没有我可以展示的图片,并以某种方式在上面加上标记?

最佳答案

可以显示整个世界并使用 MapView(或 MapFragment)在其上放​​置标记 Lite Mode :

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

标记在“部分”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.

此外,您还可以使用其他功能,如线条和多边形绘制等。

因此,使用 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(也可以通过 GoogleMapOptions.liteMode(true) 以编程方式为 MapView 设置精简模式):

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

你有这样的东西:

Google Maps Whole World

关于android - 如何显示整个世界并在其上放置标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42329186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com