嗨,在我的应用程序中,我正在显示一个片段。在那个片段中,我正在显示地图。所以我的代码看起来像:
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/innerrelativelay"
android:padding="10dp">
<TextView
android:id="@+id/storename"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Store Name:"
android:textSize="15sp"
/>
<TextView
android:id="@+id/storeaddress"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="@+id/storename"
android:text="Store Address:"
android:textSize="15sp"
/>
</RelativeLayout>
<com.google.android.gms.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mapView"
android:layout_below="@+id/innerrelativelay"
/>
</RelativeLayout>
和片段看起来像:
public class MyAccount extends SherlockFragment {
MapView map;
GoogleMap mMap;
TextView storeName,storeAddress;
SharedPreferences storeInfo,authenticationInfo;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.maplayout, container, false);
map = (MapView) v.findViewById(R.id.mapView);
map.onCreate(savedInstanceState);
mMap = map.getMap();
map.onCreate(savedInstanceState);
mMap.getUiSettings().setMyLocationButtonEnabled(false);
mMap.setMyLocationEnabled(true);
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);
mMap.animateCamera(cameraUpdate);
mMap.setMyLocationEnabled(true);
storeName = (TextView)v.findViewById(R.id.storename);
storeAddress = (TextView)v.findViewById(R.id.storeaddress);
storeInfo = getActivity().getSharedPreferences(CommonSharedPref.QCMERCHANT_STOREID, 0);
authenticationInfo = getActivity().getSharedPreferences(CommonSharedPref.QCMERCHANT_AUTHENTICATION_INFO, 0);
storeName.setText(storeName.getText().toString()+storeInfo.getString(CommonSharedPref.QCMERCHANT_STORENAME, ""));
storeAddress.setText(storeAddress.getText().toString()+storeInfo.getString(CommonSharedPref.QCMERCHANT_ADDRESS1, "")
+"\n"+storeInfo.getString(CommonSharedPref.QCMERCHANT_ADDRESS1, ""));
return v;
}
}
它向我显示正确的地图,但创建标记、显示当前位置或在给定位置移动相机无法正常工作。这个怎么做。需要帮忙。谢谢你。