0

我在我的Android應用程序中有谷歌地圖,在我的大多數Android設備上我的谷歌地圖工作正常,但在一臺設備上它我的谷歌地圖不工作。 我的谷歌地圖類是:谷歌地圖類不工作

public class Map extends Activity { 

    // Google Map 
    private GoogleMap googleMap; 
    Intent intent; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.map); 

     try { 
      // Loading map 
      initilizeMap(); 


     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

    } 

    /** 
    * function to load map. If map is not created it will create it for you 
    * */ 
    private void initilizeMap() { 
      double latitude = 0 ; 
      double longitude = 0; 

     if (googleMap == null) { 
      googleMap = ((MapFragment) getFragmentManager().findFragmentById(
        R.id.map)).getMap(); 


      intent=getIntent(); 

      String location=intent.getStringExtra("location"); 


     /*  GPS gps = new GPS(this); 
      if(gps.canGetLocation()){ // gps enabled} // return boolean true/false 

      latitude=gps.getLatitude(); // returns latitude 
      longitude=gps.getLongitude(); // returns longitude 
      } 
      */ 

     // Toast.makeText(getApplicationContext(), location, Toast.LENGTH_LONG).show(); 
      String[] arr = location.split(" ", 2); 
      latitude=Double.valueOf(arr[0]); 
      longitude=Double.valueOf(arr[1]); 



      // googleMap.setMyLocationEnabled(true); 
      // create marker 
      MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)); 

      // adding marker 
      googleMap.addMarker(marker); 
      CameraUpdate center= 
        CameraUpdateFactory.newLatLng(new LatLng(latitude, 
                  longitude)); 
       CameraUpdate zoom=CameraUpdateFactory.zoomTo(15); 

       googleMap.moveCamera(center); 
       googleMap.animateCamera(zoom); 

      // check if map is created successfully or not 

      if (googleMap == null) { 
       Toast.makeText(getApplicationContext(), 
         "Sorry! unable to create maps", Toast.LENGTH_SHORT) 
         .show(); 
      } 
     } 
    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 
     initilizeMap(); 
    } 

} 

我給這家設備logcat的是:

10-24 03:46:02.535: D/ActivityThread(3501): ACT-AM_ON_PAUSE_CALLED ActivityRecord{418378f0 [email protected] {soft.b.peopleassist/soft.b.peopleassist.Respond}} 
10-24 03:46:02.546: D/ActivityThread(3501): ACT-PAUSE_ACTIVITY handled : 1/[email protected] 
10-24 03:46:02.551: D/ThemeManager(3501): packageName=====soft.b.peopleassist 
10-24 03:46:02.551: D/ThemeManager(3501): packageName=soft.b.peopleassist 
10-24 03:46:02.551: D/RRR(3501): path=other/bottom/bottom7.png 
10-24 03:46:02.553: D/ThemeManager(3501): sIconWidth=64----sIconHeight=64 
10-24 03:46:02.555: D/ThemeManagerHH(3501): infoDrawable=72 
10-24 03:46:02.589: W/GooglePlayServicesUtil(3501): Google Play services is missing. 
10-24 03:46:02.590: W/GooglePlayServicesUtil(3501): Google Play services is missing. 
10-24 03:46:02.593: W/GooglePlayServicesUtil(3501): Google Play services is missing. 
10-24 03:46:02.596: W/GooglePlayServicesUtil(3501): Google Play services is missing. 
10-24 03:46:02.598: W/GooglePlayServicesUtil(3501): Google Play services is missing. 
10-24 03:46:02.603: W/GooglePlayServicesUtil(3501): Google Play services is missing. 
10-24 03:46:02.605: W/System.err(3501): java.lang.NullPointerException 
10-24 03:46:02.606: W/System.err(3501):  at soft.b.peopleassist.Map.initilizeMap(Map.java:76) 
10-24 03:46:02.607: W/System.err(3501):  at soft.b.peopleassist.Map.onCreate(Map.java:30) 
10-24 03:46:02.607: W/System.err(3501):  at android.app.Activity.performCreate(Activity.java:4510) 
10-24 03:46:02.608: W/System.err(3501):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050) 
10-24 03:46:02.609: W/System.err(3501):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2048) 
10-24 03:46:02.609: W/System.err(3501):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2111) 
10-24 03:46:02.610: W/System.err(3501):  at android.app.ActivityThread.access$600(ActivityThread.java:134) 
10-24 03:46:02.610: W/System.err(3501):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1251) 
10-24 03:46:02.610: W/System.err(3501):  at android.os.Handler.dispatchMessage(Handler.java:99) 
10-24 03:46:02.611: W/System.err(3501):  at android.os.Looper.loop(Looper.java:137) 
10-24 03:46:02.612: W/System.err(3501):  at android.app.ActivityThread.main(ActivityThread.java:4666) 
10-24 03:46:02.612: W/System.err(3501):  at java.lang.reflect.Method.invokeNative(Native Method) 
10-24 03:46:02.613: W/System.err(3501):  at java.lang.reflect.Method.invoke(Method.java:511) 
10-24 03:46:02.614: W/System.err(3501):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809) 
10-24 03:46:02.614: W/System.err(3501):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576) 
10-24 03:46:02.615: W/System.err(3501):  at dalvik.system.NativeStart.main(Native Method) 
10-24 03:46:02.617: W/GooglePlayServicesUtil(3501): Google Play services is missing. 
10-24 03:46:02.618: D/AndroidRuntime(3501): Shutting down VM 
10-24 03:46:02.619: W/dalvikvm(3501): threadid=1: thread exiting with uncaught exception (group=0x40e61258) 
10-24 03:46:02.624: E/AndroidRuntime(3501): FATAL EXCEPTION: main 
10-24 03:46:02.624: E/AndroidRuntime(3501): java.lang.RuntimeException: Unable to resume activity {soft.b.peopleassist/soft.b.peopleassist.Map}: java.lang.NullPointerException 
10-24 03:46:02.624: E/AndroidRuntime(3501):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2602) 
10-24 03:46:02.624: E/AndroidRuntime(3501):  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2630) 
10-24 03:46:02.624: E/AndroidRuntime(3501):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2116) 
10-24 03:46:02.624: E/AndroidRuntime(3501):  at android.app.ActivityThread.access$600(ActivityThread.java:134) 
10-24 03:46:02.624: E/AndroidRuntime(3501):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1251) 
10-24 03:46:02.624: E/AndroidRuntime(3501):  at android.os.Handler.dispatchMessage(Handler.java:99) 
10-24 03:46:02.624: E/AndroidRuntime(3501):  at android.os.Looper.loop(Looper.java:137) 
10-24 03:46:02.624: E/AndroidRuntime(3501):  at android.app.ActivityThread.main(ActivityThread.java:4666) 
10-24 03:46:02.624: E/AndroidRuntime(3501):  at java.lang.reflect.Method.invokeNative(Native Method) 
10-24 03:46:02.624: E/AndroidRuntime(3501):  at java.lang.reflect.Method.invoke(Method.java:511) 
10-24 03:46:02.624: E/AndroidRuntime(3501):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809) 
10-24 03:46:02.624: E/AndroidRuntime(3501):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576) 
10-24 03:46:02.624: E/AndroidRuntime(3501):  at dalvik.system.NativeStart.main(Native Method) 
10-24 03:46:02.624: E/AndroidRuntime(3501): Caused by: java.lang.NullPointerException 
10-24 03:46:02.624: E/AndroidRuntime(3501):  at soft.b.peopleassist.Map.initilizeMap(Map.java:76) 
10-24 03:46:02.624: E/AndroidRuntime(3501):  at soft.b.peopleassist.Map.onResume(Map.java:98) 
10-24 03:46:02.624: E/AndroidRuntime(3501):  at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1159) 
10-24 03:46:02.624: E/AndroidRuntime(3501):  at android.app.Activity.performResume(Activity.java:4584) 
10-24 03:46:02.624: E/AndroidRuntime(3501):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2588) 
10-24 03:46:02.624: E/AndroidRuntime(3501):  ... 12 more 

回答

1

顯然從您的設備不必須google play services,自使用地圖的logcat的需要google play services那這就是爲什麼它崩潰。

​​

this,這是一個衆所周知的問題,很多薑餅手機不與谷歌Play業務出貨,所以不是你需要變通辦法,檢查安裝應用程序啓動時,安全地告訴用戶他們的設備不支持它或阻止這些設備下載市場中的應用程序。

希望這能幫助你,併爲你提供線索。

+0

感謝您的線索,請告訴我如何解決這個問題? – Talib

+1

支票[post no。 #2](https://code.google.com/p/android/issues/detail?id=42543),他解釋了什麼是問題以及如何解決它。我從來沒有嘗試過,但似乎是合理的。 – Coderji

+1

或者如果你想在你檢測到用戶設備後,你檢查它沒有'谷歌播放服務',你可以指導他們到他們可以手動下載'谷歌播放服務'頁面。 [檢查這一個](http://www.androidpolice.com/2012/09/26/google-play-services-can-now-be-installed-manually-from-the-play-store/) – Coderji

0

在使用谷歌地圖API之前,您需要檢查設備上是否有谷歌播放服務。

public static boolean isGooglePlayServicesAvailable(SplashScreenActivity context) { 
     int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context); 
     if (ConnectionResult.SUCCESS == status) { 
      return true; 
     } else { 
      //GooglePlayServicesUtil.getErrorDialog(status, context, 0).show(); 
      return false; 
     } 
    } 

如果谷歌播放服務不可用,您可以導航用戶到Playstore安裝谷歌播放服務。

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+ GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE)));