2016-11-12 229 views
7

我正在嘗試使用Android Studio執行MapActivity。它必須顯示用戶的位置。ANDROID:錯誤W/DynamiteModule:未找到com.google.android.gms.google證書的本地模塊描述符類

嗯,我知道我需要一個密鑰才能使用這個API,並相信我,我至少改了四次這個密鑰......我也擁有AndroidManifest.xml中的權限。

事情是我可以在沒有用戶位置的情況下顯示地圖,但是如果我嘗試顯示他/她的位置,那麼應用程序編譯得很好,但是當我嘗試執行它時,它會停止並且我獲得此錯誤:

11-12 09:13:28.416 21576-21653/raquel.mapapplication W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found. 
11-12 09:13:28.424 21576-21653/raquel.mapapplication I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:2 
11-12 09:13:28.424 21576-21653/raquel.mapapplication I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 2 
11-12 09:13:28.432 21576-21653/raquel.mapapplication W/System: ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/m/0000000b/n/armeabi 
11-12 09:13:28.436 21576-21653/raquel.mapapplication D/GoogleCertificates: com.google.android.gms.googlecertificates module is loaded 
11-12 09:13:28.504 21576-21653/raquel.mapapplication D/GoogleCertificatesImpl: Fetched 190 Google release certificates 
11-12 09:13:28.505 21576-21653/raquel.mapapplication D/GoogleCertificatesImpl: Fetched 363 Google certificates 
11-12 09:13:31.235 21576-21576/raquel.mapapplication I/Process: Sending signal. PID: 21576 SIG: 9 

它提到一些關於谷歌證書,這就是爲什麼我想,也許它是與關鍵...但我不知道,我沒有想法是什麼,我做錯了。

謝謝你的幫助。

////////

好吧,我會嘗試張貼一些代碼...我一直在改變代碼所有的時間,但是這是我最後一次嘗試(我也試過setMyLocationEnable (真),因爲getMyLocation()已過時,但我得到了同樣的錯誤):

公共類MapsActivity擴展FragmentActivity實現OnMapReadyCallback {

private GoogleMap mMap; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_maps); 
    // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
      .findFragmentById(R.id.map); 
    mapFragment.getMapAsync(this); 
} 

@Override 
public void onMapReady(GoogleMap googleMap) { 
    mMap = googleMap; 

    Location location=mMap.getMyLocation(); 

    double lat=location.getLatitude(); 
    double lon=location.getLongitude(); 

    // Add a marker in Sydney and move the camera 
    LatLng sydney = new LatLng(lat, lon); 
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); 
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); 
} 

}

感謝回答我的人和編輯我評論的人...我仍然不太好如何格式化文本...

+0

你可以包括一些代碼,以及好嗎? –

+0

嘗試在Google Developer Console中更新項目中的SHA1密鑰並更新您的Android項目中的Google Maps API密鑰。爲了更好地理解,請確保正確執行本[文檔]中給出的步驟(https://developers.google.com/maps/documentation/android-api/signup#if-you-are-using-the-standard- google-maps-android-api),尤其是[「在哪裏獲取應用程序的SHA-1指紋」]的部分內容(https://developers.google.com/maps/documentation/android-api/signup#fingerprint) – KENdi

+3

嗨拉奎爾,你解決了嗎? (我在這裏有同樣的問題) – MiguelHincapieC

回答

0

打開sdk manager,下載/更新google play services。 並創建一個新的模擬器。

0

加載證書可能是API中的錯誤,我認爲某處任何谷歌開發人員也曾描述過,玩遊戲服務試圖登錄驗證遊戲應用程序或第三方應用程序,以便可能出錯。我對此不甚瞭解。

,但如果你仍然有放置標記用戶的麻煩,地位,你可以試試下面的代碼我測試和應用

@Override 
public void onMapReady(GoogleMap googleMap) 

{ 
    myGoogleMap = googleMap; 
    placeMarkerOnPosition(); 
} 

public void placeMarkerOnPosition() { 
//// check permissions to access resources ///////// 
if (ActivityCompat.checkSelfPermission(this, 
android.Manifest.permission.ACCESS_FINE_LOCATION) != 
PackageManager.PERMISSION_GRANTED && 
ActivityCompat.checkSelfPermission(this, 
android.Manifest.permission.ACCESS_COARSE_LOCATION) != 
PackageManager.PERMISSION_GRANTED) { 

    return; 
} 
    LocationManager locationManager = (LocationManager) 
    getSystemService(Context.LOCATION_SERVICE); 

現在是工作,你可以用兩種方式

發現
//////////////// find location if GPS provider is available (GPS should 
enable to envoke this callback) 

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, 
new LocationListener() 
{ 
@Override 
public void onLocationChanged(Location location) { 

try { 
    Geocoder geocoder = new Geocoder(getApplicationContext());        
    myLatitude = location.getLatitude(); 
    myLongitude = location.getLongitude(); 
    LatLng myPosition = new LatLng(myLatitude,myLongitude); 
    List<Address> places=geocoder.getFromLocation(myLatitude, 
    myLongitude,1); 
    myLocation = places.get(0).getSubLocality() 
       +""+places.get(0).getLocality(); 

    myGoogleMap.clear(); 
    myGoogleMap.addMarker(new 
    MarkerOptions().position(myPosition).title(myLocation)); 

    myGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(myPosition, 
                   13.5f)); 


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

    @Override 
    public void onStatusChanged(String s, int i, Bundle bundle) { 

    } 

    @Override 
    public void onProviderEnabled(String s) { 

    } 

    @Override 
    public void onProviderDisabled(String s) { 

    } 
    }); 

//////////////// checking with network providers ///////// 


if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { 


locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 
             0, new LocationListener() { 
@Override 
public void onLocationChanged(Location location) { 
myLatitude = location.getLatitude(); 
myLongitude = location.getLongitude(); 
LatLng myPosition = new LatLng(myLatitude, myLongitude); 
myGoogleMap.clear(); 
myGoogleMap.addMarker(new MarkerOptions().position(myPosition).title("My 
                  Position")); 

myGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(myPosition, 
                   13.5f)); 

}

   @Override 
       public void onStatusChanged(String s, int i, Bundle bundle) 
       { 

       } 

       @Override 
       public void onProviderEnabled(String s) { 

       } 

       @Override 
       public void onProviderDisabled(String s) { 

       } 
      }); 

     } 

    //////// Or you can find it with user recent location ////////// 

    Criteria criteria = new Criteria(); 
    String bestProvider = locationManager.getBestProvider(criteria,true); 
    Locationlocation=locationManager.getLastKnownLocation(bestProvider); 

    ////////// load your location from last recent locations //////// 
      if (location != null) { 
       Geocoder geocoder = new Geocoder(getApplicationContext()); 

       try { 
        myLatitude = location.getLatitude(); 
        myLongitude = location.getLongitude(); 
        LatLng myPosition = new LatLng(myLatitude, myLongitude); 
        List<Address> places = 
        geocoder.getFromLocation(myLatitude, myLongitude, 1); 
        myLocation = places.get(0).getSubLocality() + " " + places.get(0).getLocality(); 

        myGoogleMap.clear(); 
        myGoogleMap.addMarker(new MarkerOptions().position(myPosition).title(myLocation)); 
        myGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(myPosition, 13.5f)); 


       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
+0

提示:你有很多代碼 - 非常懶散地格式化/縮進。請使用**預覽**窗口確保您不會轉儲一些代碼亂七八糟的東西,但是人們會發現足夠可讀的東西。 – GhostCat

相關問題