以编程方式设置GoogleMapOptions [英] Setting GoogleMapOptions programmatically

查看:160
本文介绍了以编程方式设置GoogleMapOptions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  GoogleMap map =((MapFragment)getFragmentManager()。findFragmentById(R。 id.MapFragment_map_Fragment))的GetMap(); 

这里有我的选择:

  GoogleMapOptions options = new GoogleMapOptions(); 
options.mapType(GoogleMap.MAP_TYPE_SATELLITE);


lockquote

在创建地图时应用这些选项,执行以下
之一:



如果您使用MapFragment,请使用
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);


I am inflating my fragment like this:

GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.MapFragment_map_Fragment)).getMap(); 

and here I have my options:

GoogleMapOptions options = new GoogleMapOptions();
options.mapType(GoogleMap.MAP_TYPE_SATELLITE);

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

For example:

GoogleMap googleMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map_fragment)).getMap();
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);

这篇关于以编程方式设置GoogleMapOptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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