2015-10-21 90 views
-2

我在我的android應用程序中實現谷歌地圖API v2。該應用程序在所有設備上都能正常工作,但不適用於棒棒糖設備。應用程序崩潰在棒棒糖。我沒有搜索這個問題,但沒有得到一個合理的解決方案。如果有人知道這個問題,請幫助我。我會非常感謝谷歌地圖應用程序崩潰在棒棒糖android

+0

添加您的logcat這裏.. !! – AndiGeeky

+0

請顯示您的日誌 –

+0

對不起,我沒有5.0的設備來調試代碼。我正在4.4.4上測試它,它的工作正常。但我的客戶端5.0,當他測試應用程序,然後應用程序崩潰 –

回答

0

嘗試使用Android Studio生成Google地圖活動。

+0

對不起,我沒有得到你 –

+0

閱讀步驟3 https://developers.google.com/maps/documentation/android-api/start – phuanh004

2

可能是您正在嘗試通過 LocationManager類獲取位置。這種方式完美地適用於preLollipop設備。但是在棒棒糖中它不起作用。現在再次谷歌發佈了一個新的API,但他們沒有正確地更新文檔。這裏有一個獲取演示代碼的位置,可以讓您在使用新的/最新的位置服務API的某個時間間隔後獲取位置對象。

import android.app.Activity; 
import android.location.Location; 
import android.os.Bundle; 
import android.util.Log; 

import com.google.android.gms.common.ConnectionResult; 
import com.google.android.gms.common.api.GoogleApiClient; 
import com.google.android.gms.location.LocationListener; 
import com.google.android.gms.location.LocationRequest; 
import com.google.android.gms.location.LocationServices; 

/** 
* Created by skarim on 10/29/15. 
*/ 
public class GetLocationAfterCertainInterval extends Activity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener , 
     LocationListener { 
    GoogleApiClient apiClient=null; 
    LocationRequest mLocationRequest=null; 
    private int locationInterval,fastedInterval; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     // Initialize Your View here. 
     setLocationLocationRequest(); 
    } 

    @Override 
    public void onDestroy() { 
     // Your need of location update is done. So you have to stop the apiClient. 
     super.onDestroy(); 
     this.apiClient.disconnect(); 
    } 


    private void setLocationLocationRequest() { 

     try { 
      apiClient=new GoogleApiClient.Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(LocationServices.API).build(); 

      mLocationRequest = new LocationRequest(); 
      mLocationRequest.setInterval(29000); 
      mLocationRequest.setFastestInterval(5000); 
      mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); 
      apiClient.connect(); 

     }catch (Exception e){ 
      Log.d("LS", e.getMessage() == null ? "" : e.getMessage()); 
     } 

    } 
    @Override 
    public void onConnected(Bundle bundle) { 
     // Your API Client is connected. So can request for updates 
     LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, mLocationRequest, this); 
    } 

    @Override 
    public void onConnectionSuspended(int i) { 

    } 

    @Override 
    public void onLocationChanged(Location location) { 
     // After your desired interval This api will give you the Location Object. 

    } 

    @Override 
    public void onConnectionFailed(ConnectionResult connectionResult) { 

    } 


} 

有關此API的更多詳細信息,你可以看到this Developer Link

我的相關Answer is here

對不起壞English.Thanks

相關問題