vli*_*o20 7 android google-maps android-fragments
我像这样膨胀我的片段:
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.MapFragment_map_Fragment)).getMap();
Run Code Online (Sandbox Code Playgroud)
在这里我有我的选择:
GoogleMapOptions options = new GoogleMapOptions();
options.mapType(GoogleMap.MAP_TYPE_SATELLITE);
Run Code Online (Sandbox Code Playgroud)
在文档中,我看到我需要使用它:
要在创建地图时应用这些选项,请执行以下操作之一:
如果您使用的是MapFragment,请使用MapFragment.newInstance(GoogleMapOptions选项)静态工厂方法构建片段并传入自定义配置选项.
但我不明白我怎么想用这个.
Les*_*zek 13
我认为GoogleMapOptions
只有在以编程方式创建地图视图时才能使用(将选项传递给MapFragment.newInstance()
方法 - 文档).你是MapFragment
从xml 膨胀,所以你不能以这种方式使用它们.在您的情况下,您仍然可以使用GoogleMap
setter或更改地图选项UiSettings
.
例如:
GoogleMap googleMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map_fragment)).getMap();
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
Run Code Online (Sandbox Code Playgroud)
小智 5
我以编程方式使用 LiteMode,而不是在 XML 文件中设置 MapView 和 MapFragment 的属性。尝试这个:
GoogleMapOptions googleMapOptions = new GoogleMapOptions().liteMode(true);
googleMap.setMapType(googleMapOptions.getMapType());
Run Code Online (Sandbox Code Playgroud)
或者在 XML 中:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mapslastapp.MapsActivity"
map:liteMode="true"
map:cameraZoom="16"
map:mapType="normal"/>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4874 次 |
最近记录: |