Hes*_*sam 5 android android-mapview google-maps-android-api-2
我有一个包含MapView的片段.我在XML文件中添加了这个视图,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
map:uiCompass="true"
android:background="#00000000" />
Run Code Online (Sandbox Code Playgroud)
我已将它链接到我的代码,如下所示:
public class HotSpotsFragment extends MainFragment implements LocationListener {
private static final String TAG = "HotSpotsFragment";
private Context context;
private LocationManager locationManager;
private MapView mapView;
private GoogleMap googleMap;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// create view
View view = inflater.inflate(R.layout.fragment_hot_spots, container, false);
// Getting context
context = getActivity().getApplicationContext();
// Make sure user's device supports Google play services
try {
MapsInitializer.initialize(getActivity());
} catch (GooglePlayServicesNotAvailableException e) {
Log.e(TAG, "Google play service is not available.");
Toast.makeText(getActivity().getApplicationContext(), R.string.hot_spots_not_supported, Toast.LENGTH_LONG).show();
return null;
}
Log.i(TAG, "Google play service is available.");
mapView = (MapView) view.findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
googleMap = ((MapView) view.findViewById(R.id.mapView)).getMap();
if(googleMap == null) {
Toast.makeText(getActivity().getApplicationContext(), R.string.hot_spots_not_supported, Toast.LENGTH_LONG).show();
return null;
}
Log.i(TAG, "View created");
return view;
}
.
.
.
}
Run Code Online (Sandbox Code Playgroud)
我想添加添加选项到我的地图视图.基于GoogleMapOptions上提到的内容,"在以编程方式向应用程序添加地图时(而不是通过XML),可以使用这些选项.如果使用的是MapFragment,则可以使用静态工厂方法newInstance传递这些选项(GoogleMapOptions).如果您使用的是MapView,则可以使用构造函数MapView(Context,GoogleMapOptions)传递这些选项." 最后我的情况是," 如果你使用XML添加地图,那么你可以使用自定义XML标签来应用这些选项. "
我没有找到任何示例来展示如何通过XML添加选项.我想在我的XML代码中添加zOrderOnTop ="true".
任何建议将不胜感激.谢谢
这很简单
<com.google.android.gms.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
map:uiCompass="true"
map:zOrderOnTop="true"
map:uiZoomControls="true"
android:background="#00000000" />
Run Code Online (Sandbox Code Playgroud)
然而,新问题是添加map:zOrderOnTop="true"将从屏幕中删除叠加对象,如ZoomIn/ZoomOut :(有关更多信息,请参阅此链接.
| 归档时间: |
|
| 查看次数: |
15576 次 |
| 最近记录: |