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