2016-02-08 46 views
0

我與show map有問題,但是爲什麼要顯示empty map?!像圖像空映射當在android studio中運行代碼

sample

我給你介紹我的代碼 我把關鍵文件release/res/values/google_map_api.xml,也把在debug/res/values/google_map_api.xml

<resources> 
    <string name="google_maps_key" translatable="false" templateMergeStrategy="preserve"> 
     AIzaSyDci-------------hSik 
    </string> 
</resources> 

我也把我的鑰匙androidManifest.xml

<meta-data 
      android:name="com.google.android.geo.API_KEY" 
      android:value="AIzaSyDci-------------hSik" /> 

MapActivity.java的代碼

public class MapsActivity extends AppCompatActivity implements 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; 

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

注意:使用手機Galaxy Note不是emulator android studio。

+0

你可以添加的logcat和'activity_maps'佈局文件? – Hein

+0

嘗試使用'MagFragment'而不是'SupportMapFragment' –

+0

我不明白如何添加logcat? – SaharSafran

回答

0

請檢查下表現

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

<permission 
     android:name="com.example.map.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature" /> 
<permission 
      android:name="com.example.map.permission.MAPS_RECEIVE" 
      android:protectionLevel="signature"/> 
<uses-permission android:name="com.example.map.permission.MAPS_RECEIVE"/> 
+0

在添加權限時未改變結果 – SaharSafran

+0

您是否已通過Google API Console啓用Google Maps Android API? – Nithinjith

+0

是的,我從Google API控制檯獲取密鑰 – SaharSafran

0

允許這部分在加入Android清單

<meta-data android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" /> 
+0

相同的結果不顯示地圖 – SaharSafran