0

嗨,在我的应用程序中,我正在显示一个片段。在那个片段中,我正在显示地图。所以我的代码看起来像:

   <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;
    }
}

它向我显示正确的地图,但创建标记、显示当前位置或在给定位置移动相机无法正常工作。这个怎么做。需要帮忙。谢谢你。

4

1 回答 1

0

更新 尝试将片段的布局更改为

<fragment
    android:id="@+id/mapView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.MapFragment" />

此外,您似乎还没有初始化标记。这就是为什么标记不可见..如果你需要如何做的指针..有一个非常好的tutrial页面......

http://www.vogella.com/articles/AndroidGoogleMaps/article.html

从这里https://developers.google.com/maps/documentation/android/v1/hello-mapview,您可以看到

自 2012 年 12 月 3 日起正式弃用 Google Maps Android API 版本 1

所以你不应该再使用 MapView 了。我建议您改用 MapFragment。在此处查看优秀的文档:https ://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/MapFragment

于 2013-09-20T11:19:21.290 回答