以编程方式设置GoogleMapOptions [英] Setting GoogleMapOptions programmatically
问题描述
GoogleMap map =((MapFragment)getFragmentManager()。findFragmentById(R。 id.MapFragment_map_Fragment))的GetMap();
这里有我的选择:
GoogleMapOptions options = new GoogleMapOptions();
options.mapType(GoogleMap.MAP_TYPE_SATELLITE);
在 在创建地图时应用这些选项,执行以下 如果您使用MapFragment,请使用 但我不明白我是怎么用这个的。 我认为你可以使用 例如: I am inflating my fragment like this: and here I have my options: In the documentation I see that I need to use this: To apply these options when you are creating a map, do one of the
following: If you are using a MapFragment, use the
MapFragment.newInstance(GoogleMapOptions options) static factory
method to construct the fragment and pass in your custom configured
options. But I don't understand how am I suppose to use this. I think you can use For example:
这篇关于以编程方式设置GoogleMapOptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
lockquote
之一:
MapFragment。 newInstance(GoogleMapOptions选项)静态工厂
方法来构造片段并传入您的自定义配置
选项。
GoogleMapOptions
仅当您以编程方式创建地图视图时(将选项传递给 MapFragment.newInstance()
方法 - docs )。你从xml中膨胀 MapFragment
,所以你不能以这种方式使用它们。在你的情况下,你仍然可以通过使用 GoogleMap
setters或 UiSettings
来更改地图选项。
使用GoogleMap使用GoogleMap =((SupportMapFragment)getSupportFragmentManager()findFragmentById(R.id。 .map_fragment))的GetMap();
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
googleMap.getUiSettings()。setMyLocationButtonEnabled(true);
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.MapFragment_map_Fragment)).getMap();
GoogleMapOptions options = new GoogleMapOptions();
options.mapType(GoogleMap.MAP_TYPE_SATELLITE);
GoogleMapOptions
only if you are creating map view programmatically(passing options to MapFragment.newInstance()
method - docs). You are inflating MapFragment
from xml so you wont be able to use them in that way. In your case you can still change map options by using GoogleMap
setters or UiSettings
.GoogleMap googleMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map_fragment)).getMap();
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);