2

我收到此错误:

android.view.InflateException: Binary XML file line #13: Error inflating class com.google.android.maps.MapView

这是我的 MapView 类

public class MapViewActivity extends BaseFragment {
private TextView mTvTitle;
private View mView;

/*mapview members*/
private MapView mMapView;
private MapController mapController;
private LocationManager locationManager;
private MyLocationOverlay myLocationOverlay;
private static final int DEFAULT_ZOOM = 14;
private GeoUpdateHandler locationListener =  new GeoUpdateHandler();

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}


@Override
public void onResume() {
    super.onResume();
    myLocationOverlay.enableMyLocation();
    myLocationOverlay.enableCompass();
}

@Override
public void onPause() {
    super.onPause();
    locationManager.removeUpdates(locationListener);
    myLocationOverlay.disableMyLocation();
    myLocationOverlay.disableCompass();
}

@Override
public void onDestroy() {
    super.onDestroy();
    myLocationOverlay.disableMyLocation();
    myLocationOverlay.disableCompass();
}

@SuppressWarnings("unchecked")
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mView = inflater.inflate(R.layout.map_activity, container, false);
    mTvTitle  = (TextView) mView.findViewById(R.id.tvTitle);
    mTvTitle.setText(getResources().getString(R.string.top_tab_around));

    mMapView = (MapView) mView.findViewById(R.id.mvMapAroundMe);

    BindMap();
    return mView;
}

private void BindMap() {

    mMapView.preLoad();
    mMapView.setBuiltInZoomControls(true);
    mMapView.setSatellite(false);
    mapController = mMapView.getController();
    mapController.setZoom(14); // Zoom 1 is world view

    locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);

    myLocationOverlay = new MyLocationOverlay(getActivity(), mMapView);
    mMapView.getOverlays().add(myLocationOverlay);

    Drawable drawable = this.getResources().getDrawable(R.drawable.pin);
    List<Overlay> mapOverlays = mMapView.getOverlays();
    MyItemizedOverlay itemizedoverlay = new MyItemizedOverlay(drawable, getActivity());
    OverlayItem oItem = new OverlayItem(GeopointFactory(33.446886, -86.057426),  "title", "title2");
    itemizedoverlay.addOverlay(oItem);
    mapOverlays.add(itemizedoverlay);
    mapOverlays.add(itemizedoverlay);

    myLocationOverlay.runOnFirstFix(new Runnable() {
        public void run() {
            animateToPlaceOnMap ( GeopointFactory(33.446886, -86.057426) );
        }
    });
}


public class GeoUpdateHandler implements LocationListener {
    @Override
    public void onLocationChanged(Location location) {
        mapController.animateTo( GeopointFactory(location.getLatitude(), location.getLongitude()));
    }

    @Override
    public void onProviderDisabled(String provider) {
    }

    @Override
    public void onProviderEnabled(String provider) {
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }
}


private class MyItemizedOverlay extends ItemizedOverlay {
    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    Context mContext;

    public MyItemizedOverlay(Drawable marker) {
        super(boundCenterBottom(marker));
    }

    public MyItemizedOverlay(Drawable marker, Context context) {
        super(boundCenterBottom(marker));
        mContext = context;
    }

    public void addOverlay(OverlayItem overlay) {
        mOverlays.add(overlay);
        populate();
    }

    @Override
    protected OverlayItem createItem(int i) {
        return mOverlays.get(i);
    }

    @Override
    public int size() {
        return mOverlays.size();
    }

    @Override
    protected boolean onTap(int index) {
        final int tempIndex = index;
        OverlayItem item = mOverlays.get(index);
        AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
        dialog.setTitle(item.getTitle());
        dialog.setMessage(item.getSnippet());

        dialog.setPositiveButton("פרטים",new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

            }
        });
        dialog.show();
        return true;
    }
}

private void animateToPlaceOnMap(final GeoPoint geopoint) {
    mMapView.post(new Runnable() {
        @Override
        public void run() {
            mMapView.invalidate();
            mapController.animateTo(geopoint);
            mapController.setZoom(DEFAULT_ZOOM);
        }
    });
}

private GeoPoint GeopointFactory(double latitude, double longitude) {
    int lat = (int) (latitude * 1E6);
    int lng = (int) (longitude * 1E6);
    return new GeoPoint(lat, lng);
}

}

这是我的清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="il.co.toeat" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.VIBRATE" />


<application android:label="@string/app_name" android:icon="@drawable/icon" android:name=".views.MainApplication">
    <uses-library android:name="com.google.android.maps" />

    <activity  android:name=".views.SplashActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar" android:noHistory="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".views.ViewportActivity"
              android:windowSoftInputMode="adjustPan|adjustResize"
              android:label="@string/app_name"
              android:configChanges="locale"
              android:screenOrientation="portrait"
              android:theme="@android:style/Theme.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>
</application>

4

1 回答 1

-1

您不能使用 Google Map API 以这种方式进行操作。

从 2012 年 12 月起,您可以将 MapFragment 和 SupportMapFragment 与 Google Map API v2 一起使用,更多信息请参见:https ://developers.google.com/maps/documentation/android/

编辑

我想你不理解我。您不应该以您的方式将 MapView 放入 Fragment 中。

通常不会在简单的 Fragment 中使用 MapView(在新的 MapFragments 之前)。有一个允许它的黑客,你可以在这里阅读它https://stackoverflow.com/a/8126287/1233021 但我认为当你不需要做任何开销时最好使用新的 MapFragments ......他们自 12 月 12 日起可用。链接在上一条消息中。

顺便说一句:有一个问题,但有其他错误https://stackoverflow.com/a/9448871/1233021

于 2012-12-27T20:54:11.847 回答