片段中的Android MapView

片段中的Android MapView,第1张

片段中的Android MapView

来自Josh Holtz在GitHub上的示例

您应该添加

MapView
在你
Layout
喜欢

 <com.google.android.gms.maps.MapView     android:id="@+id/mapview"    android:layout_width="fill_parent"     android:layout_height="fill_parent" />

并实现你的

Fragment
喜欢

public class SomeFragment extends Fragment {MapView mapView;GoogleMap map;@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)          {    View v = inflater.inflate(R.layout.some_layout, container, false);    // Gets the MapView from the XML layout and creates it    mapView = (MapView) v.findViewById(R.id.mapview);    mapView.onCreate(savedInstanceState);    // Gets to GoogleMap from the MapView and does initialization stuff    map = mapView.getMap();    map.getUiSettings().setMyLocationButtonEnabled(false);    map.setMyLocationEnabled(true);    // Needs to call MapsInitializer before doing any CameraUpdateFactory calls    try {        MapsInitializer.initialize(this.getActivity());    } catch (GooglePlayServicesNotAvailableException e) {        e.printStackTrace();    }    // Updates the location and zoom of the MapView    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10);    map.animateCamera(cameraUpdate);    return v;}@Overridepublic void onResume() {    mapView.onResume();    super.onResume();}@Overridepublic void onDestroy() {    super.onDestroy();    mapView.onDestroy(); } @Override public void onLowMemory() {    super.onLowMemory();    mapView.onLowMemory();  }}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5478483.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-12
下一篇2022-12-12

发表评论

登录后才能评论

评论列表(0条)

    保存