0

地圖不顯示,不知道爲什麼。我無法弄清楚代碼中有什麼問題,如果問題出在xml或java中......即在我的應用程序中有一個額外的東西,它所有的運行都很流暢,但是當我點擊按鈕去MapActivity爆炸錯誤的膨脹類的片段,我無法解決的錯誤

的Manifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.mobimapa" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk android:minSdkVersion="8" /> 

    <permission 
      android:name="com.mobimapa.permission.MAPS_RECEIVE" 
      android:protectionLevel="signature"/> 

    <uses-permission android:name="com.mobimapa.permission.MAPS_RECEIVE"/> 

    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.WRITE_SETTINGS" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.VIBRATE" /> 
    <uses-permission android:name="com.mobimapa.permission.MAPS_RECEIVE"/> 


    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 


    <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true"/> 


    <application 
     android:allowBackup="true"   
     android:icon="@drawable/icon" 
     android:label="@string/app_name" > 
     <activity 
      android:name="com.mobimapa.AndroidPHPConnectionDemo" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name="com.mobimapa.MapActivity" 
      android:label="@string/app_name" /> 
     <activity 
      android:name="com.mobimapa.GetProcessosUser" 
      android:label="@string/app_name" /> 
     <activity 
      android:name="com.mobimapa.GetProcessosDono" 
      android:label="@string/app_name" /> 
     <activity 
      android:name="com.mobimapa.UserPage" 
      android:label="@string/app_name" /> 
     <activity 
      android:name="com.mobimapa.Anotacao" 
      android:label="@string/app_name" /> 
     <activity 
      android:name="com.mobimapa.GetProcesso" 
      android:label="@string/app_name" /> 
     <activity 
      android:name=".ProximityActivity" 
      android:label="@string/app_name" > 
      <intent-filter > 
       <action android:name="com.mobimapa.activity.proximity"/> 
       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 

     <activity 
      android:name=".NotificationView" 
      android:label="@string/app_name" > 
      <intent-filter > 
       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 

     <meta-data 
    android:name="com.google.android.maps.v2.API_KEY" 
    android:value="AIzaSyDb8wLvH5QSeBCUS-dmd-snzMYhHeA5lUQ"/> 

    </application> 

</manifest> 

MapActivity.java

public class MapActivity extends FragmentActivity { 

    GoogleMap googleMap; 
    LocationManager locationManager; 
    PendingIntent pendingIntent; 
    SharedPreferences sharedPreferences; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.map); 

     // Getting Google Play availability status 
     int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext()); 

     // Showing status 
     if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available 

      int requestCode = 10; 
      Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode); 
      dialog.show(); 

     }else { // Google Play Services are available 

      // Getting reference to the SupportMapFragment of activity_main.xml 
      SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); 

      // Getting GoogleMap object from the fragment 
      googleMap = fm.getMap(); 

      // Enabling MyLocation Layer of Google Map 
      googleMap.setMyLocationEnabled(true); 

      // Getting LocationManager object from System Service LOCATION_SERVICE 
      locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 

      // Opening the sharedPreferences object 
      sharedPreferences = getSharedPreferences("location", 0); 

      // Getting stored latitude if exists else return 0 
      String lat = sharedPreferences.getString("lat", "0"); 

      // Getting stored longitude if exists else return 0 
      String lng = sharedPreferences.getString("lng", "0"); 

      // Getting stored zoom level if exists else return 0 
      String zoom = sharedPreferences.getString("zoom", "0"); 

      // If coordinates are stored earlier 
      if(!lat.equals("0")){ 

       // Drawing circle on the map 
       drawCircle(new LatLng(Double.parseDouble(lat), Double.parseDouble(lng))); 

       // Drawing marker on the map 
       drawMarker(new LatLng(Double.parseDouble(lat), Double.parseDouble(lng))); 

       // Moving CameraPosition to previously clicked position 
       googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(Double.parseDouble(lat), Double.parseDouble(lng)))); 

       // Setting the zoom level in the map 
       googleMap.animateCamera(CameraUpdateFactory.zoomTo(Float.parseFloat(zoom))); 

      } 

      googleMap.setOnMapClickListener(new OnMapClickListener() { 

       @Override 
       public void onMapClick(LatLng point) { 

        // Removes the existing marker from the Google Map 
        googleMap.clear(); 

        // Drawing marker on the map 
        drawMarker(point); 

        // Drawing circle on the map 
        drawCircle(point); 

        // This intent will call the activity ProximityActivity 
        Intent proximityIntent = new Intent("com.mobimapa.activity.proximity"); 

        // Creating a pending intent which will be invoked by LocationManager when the specified region is 
        // entered or exited 
        pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, proximityIntent,Intent.FLAG_ACTIVITY_NEW_TASK); 

        // Setting proximity alert 
        // The pending intent will be invoked when the device enters or exits the region 20 meters 
        // away from the marked point 
        // The -1 indicates that, the monitor will not be expired 
        locationManager.addProximityAlert(point.latitude, point.longitude, 20, -1, pendingIntent); 

        /** Opening the editor object to write data to sharedPreferences */ 
        SharedPreferences.Editor editor = sharedPreferences.edit(); 

        /** Storing the latitude of the current location to the shared preferences */ 
        editor.putString("lat", Double.toString(point.latitude)); 

        /** Storing the longitude of the current location to the shared preferences */ 
        editor.putString("lng", Double.toString(point.longitude)); 

        /** Storing the zoom level to the shared preferences */ 
        editor.putString("zoom", Float.toString(googleMap.getCameraPosition().zoom)); 

        /** Saving the values stored in the shared preferences */ 
        editor.commit(); 

        Toast.makeText(getBaseContext(), "Proximity Alert is added", Toast.LENGTH_SHORT).show(); 

       } 
      }); 

      googleMap.setOnMapLongClickListener(new OnMapLongClickListener() { 
       @Override 
       public void onMapLongClick(LatLng point) { 
        Intent proximityIntent = new Intent("com.mobimapa.activity.proximity"); 

        pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, proximityIntent,Intent.FLAG_ACTIVITY_NEW_TASK); 

        // Removing the proximity alert 
        locationManager.removeProximityAlert(pendingIntent); 

        // Removing the marker and circle from the Google Map 
        googleMap.clear(); 

        // Opening the editor object to delete data from sharedPreferences 
        SharedPreferences.Editor editor = sharedPreferences.edit(); 

        // Clearing the editor 
        editor.clear(); 

        // Committing the changes 
        editor.commit(); 

        Toast.makeText(getBaseContext(), "Proximity Alert is removed", Toast.LENGTH_LONG).show(); 
       } 
      }); 
     } 
    } 

    private void drawMarker(LatLng point){ 
     // Creating an instance of MarkerOptions 
     MarkerOptions markerOptions = new MarkerOptions(); 

     // Setting latitude and longitude for the marker 
     markerOptions.position(point); 

     // Adding marker on the Google Map 
     googleMap.addMarker(markerOptions); 
    } 

    private void drawCircle(LatLng point){ 

     // Instantiating CircleOptions to draw a circle around the marker 
     CircleOptions circleOptions = new CircleOptions(); 

     // Specifying the center of the circle 
     circleOptions.center(point); 

     // Radius of the circle 
     circleOptions.radius(20); 

     // Border color of the circle 
     circleOptions.strokeColor(Color.BLACK); 

     // Fill color of the circle 
     circleOptions.fillColor(0x30ff0000); 

     // Border width of the circle 
     circleOptions.strokeWidth(2); 

     // Adding the circle to the GoogleMap 
     googleMap.addCircle(circleOptions); 

    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 
} 

map.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MapActivity"> 

    <fragment 
     class="com.mobimapa.MapActivity" 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</RelativeLayout> 

logcat的

3月8日至28日:08:51.950:E/AndroidRuntime(5592):了java.lang.RuntimeException:無法啓動活動ComponentInfo {com.mobimapa/COM。 mobimapa.MapActivity}:android.view.InflateException:二進制XML文件行#7:錯誤充氣類片段

回答

1

你應該有SupportMapFragment

<fragment 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="fill_parent" 
     android:name="com.google.android.gms.maps.SupportMapFragment"/> 

確保您擁有正確的進口。

import android.support.v4.app.FragmentActivity; 
import com.google.android.gms.maps.SupportMapFragment; 
+0

謝謝,但現在我還有一個GooglePlayServicesUtil(824):谷歌Play商店丟失...... – JPatacas

+0

@JPatacas你需要對谷歌播放服務支持的一種手段。在真實設備上進行測試 – Raghunandan

+0

@JPatacas地圖是谷歌播放服務的一部分。因此請在使用地圖http://developer.android.com/training/location/retrieve-current.html之前進行檢查。檢查主題**檢查Google Play服務** – Raghunandan