2014-10-29 16 views
0

谷歌地圖V2的黑屏我在Android應用集成谷歌地圖V2。它顯示縮放按鈕和谷歌徽標的空白屏幕。 其保存的實例也是空的。我現在用調試證書籤署了我的應用程序,但是在我用release.store簽署的第一個應用程序中。顯示錯誤之前,如不與谷歌服務器聯繫。當我與
簽名應用debug.store它示出了在ADB響應像Android應用顯示了變焦按鈕和谷歌的標誌

地圖= [email protected]

援助= com.google.android。 [email protected]

AIC = NULL

Android清單

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.bilawalkhan.pakistanmap" > 
    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
    <!-- The following two permissions are not required to use 
     Google Maps Android API v2, but are recommended. --> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
    <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true"/> 
    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name=".Map" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <meta-data 
      android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" /> 
     <meta-data 
      android:name="com.google.android.maps.v2.API_KEY" 
      android:value="AIzaSyCLgSPDsNfVrGFPO2636kWMXIAaZu2f43p"/> 
    </application> 

</manifest> 

Main_Activity是

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_map); 
    // Get a handle to the Map Fragment 
    GoogleMap map = ((MapFragment) getFragmentManager() 
      .findFragmentById(R.id.map)).getMap(); 

    LatLng sydney = new LatLng(-33.867, 151.206); 

    map.setMyLocationEnabled(true); 
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13)); 

    map.addMarker(new MarkerOptions() 
      .title("Sydney") 
      .snippet("The most populous city in Australia.") 
      .position(sydney)); 
} 

map.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
tools:context=".Map"> 
<fragment 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:name="com.google.android.gms.maps.MapFragment"/> 

其調試器顯示這樣的。

map = [email protected] 
aid = [email protected]c070 
>aic = null 

logcat中顯示:

10-29 18:40:44.200 3621-3806/com.bilawalkhan.maptesting D/REQUEST﹕ Connection opened to:https://clients4.google.com/glm/mmap/api 
10-29 18:40:44.200 3621-3806/com.bilawalkhan.maptesting D/REQUEST﹕ Open Connection 
10-29 18:40:45.640 1958-2182/com.bluestacks.gamepophome D/[InMobi]-[Analytics]-4.4.3﹕ Http Status Code: 200 
10-29 18:40:45.640 1958-2182/com.bluestacks.gamepophome D/[InMobi]-[Analytics]-4.4.3﹕ IMAppDatabaseManager->deleteEvents 
10-29 18:40:45.640 1958-2182/com.bluestacks.gamepophome D/[InMobi]-[Analytics]-4.4.3﹕ Ping Response: {"success":true} 
10-29 18:40:45.700 3621-3806/com.bilawalkhan.maptesting D/REQUEST﹕ Processing DataRequest: [email protected] 
10-29 18:40:45.720 3621-3806/com.bilawalkhan.maptesting D/REQUEST﹕ Processing DataRequest: [email protected] 
10-29 18:40:45.730 3621-3806/com.bilawalkhan.maptesting D/REQUEST﹕ Processing DataRequest: [email protected] 
10-29 18:40:45.820 3621-3806/com.bilawalkhan.maptesting D/REQUEST﹕ Processing DataRequest: [email protected] 
10-29 18:40:45.820 3621-3795/com.bilawalkhan.maptesting D/USER_EVENTS﹕ Event: type=22, status: fb, data: 1510 
10-29 18:40:45.830 3621-3795/com.bilawalkhan.maptesting D/USER_EVENTS﹕ Event: type=22, status: lb, data: 1630 
10-29 18:40:45.830 3621-3795/com.bilawalkhan.maptesting D/USER_EVENTS﹕ Event: type=22, status: flbs, data: fb=1510|lb=1630|s=1100 
10-29 18:40:45.830 3621-3806/com.bilawalkhan.maptesting D/REQUEST﹕ DRD(0): 62|75|75|147, 1s, 1kb 
10-29 18:40:45.830 3621-3806/com.bilawalkhan.maptesting D/REQUEST﹕ Close 
10-29 18:41:08.790 1898-2812/com.bluestacks.bstfolder D/dalvikvm﹕ GC_FOR_ALLOC freed 606K, 24% free 2686K/3508K, paused 10ms, total 10ms 
10-29 18:41:15.690 1958-2182/com.bluestacks.gamepophome D/[InMobi]-[Analytics]-4.4.3﹕ NetworkManager->handleMessag: msg:{ when=-40ms what=1001 target=android.os.Handler } 
10-29 18:41:15.700 1958-2182/com.bluestacks.gamepophome D/[InMobi]-[Analytics]-4.4.3﹕ IMAppDatabaseManager->getEvents 
10-29 18:41:15.710 1958-2182/com.bluestacks.gamepophome D/[InMobi]-[Analytics]-4.4.3﹕ PayloadBuilder->getPayloadList: 
10-29 18:41:53.870 1898-2812/com.bluestacks.bstfolder D/dalvikvm﹕ GC_FOR_ALLOC freed 606K, 24% free 2678K/3508K, paused 0ms, total 0m 
+0

'我整合谷歌地圖一個簡單的API密鑰,但一個V2在我的Android app' ....我太多,和它的作品對我來說... – Selvin 2014-10-29 10:24:20

+0

請閱讀[問]) – mithrop 2014-10-29 10:25:24

+0

但它不適合我 – Bilawal 2014-10-29 10:25:26

回答

-1

嘗試這樣的:

layout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <fragment 
     android:id="@+id/map" 
     android:name="com.google.android.gms.maps.MapFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

</RelativeLayout> 

MainActivity.java

public class MainActivity extends Activity { 

    // Google Map 
    private GoogleMap googleMap; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.layout); 

     try { 
      // Loading map 
      initilizeMap(); 

      // Changing map type 
      googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); 
      // googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); 
      // googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); 
      // googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN); 
      // googleMap.setMapType(GoogleMap.MAP_TYPE_NONE); 

      // Showing/hiding your current location 
      googleMap.setMyLocationEnabled(true); 

      // Enable/Disable zooming controls 
      googleMap.getUiSettings().setZoomControlsEnabled(false); 

      // Enable/Disable my location button 
      googleMap.getUiSettings().setMyLocationButtonEnabled(true); 

      // Enable/Disable Compass icon 
      googleMap.getUiSettings().setCompassEnabled(true); 

      // Enable/Disable Rotate gesture 
      googleMap.getUiSettings().setRotateGesturesEnabled(true); 

      // Enable/Disable zooming functionality 
      googleMap.getUiSettings().setZoomGesturesEnabled(true); 

      double latitude = 21.3235752; 
      double longitude =74.1881265; 

      // lets place some 10 random markers 

       // random latitude and logitude 
       double[] randomLocation = createRandLocation(latitude, 
         longitude); 

       // Adding a marker 
       MarkerOptions marker = new MarkerOptions().position(
         new LatLng(randomLocation[0], randomLocation[1])) 
         .title(" Mapview Test "); 



        //marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)); 
       marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)); 
       googleMap.addMarker(marker); 

       // Move the camera to last position with a zoom level 

        CameraPosition cameraPosition = new CameraPosition.Builder() 
          .target(new LatLng(randomLocation[0], 
            randomLocation[1])).zoom(15).build(); 

        googleMap.animateCamera(CameraUpdateFactory 
          .newCameraPosition(cameraPosition)); 



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

    } 

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

    /** 
    * function to load map If map is not created it will create it for you 
    * */ 
    @SuppressLint("NewApi") 
    private void initilizeMap() { 
     if (googleMap == null) { 
      googleMap = ((MapFragment) getFragmentManager().findFragmentById(
        R.id.map)).getMap(); 

      // check if map is created successfully or not 
      if (googleMap == null) { 
       Toast.makeText(getApplicationContext(), 
         "Sorry! unable to create maps", Toast.LENGTH_SHORT) 
         .show(); 
      } 
     } 
    } 

    /* 
    * creating random postion around a location for testing purpose only 
    */ 
    private double[] createRandLocation(double latitude, double longitude) { 

     return new double[] { latitude + ((Math.random() - 0.5)/500), 
       longitude + ((Math.random() - 0.5)/500), 
       150 + ((Math.random() - 0.5) * 10) }; 
    } 
} 

清單權限和API

<permission 
     android:name="com.example.mapexdemo.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature" /> 



    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

    <!-- Required to show current location --> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

    <!-- meta-data before </application> tag --> 
     <meta-data 
      android:name="com.google.android.maps.v2.API_KEY" 
      android:value="AIzaSyDxEkfvGvKy.........your api key" /> 

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

希望這可以幫助你! – 2014-10-29 12:54:37

+0

非常感謝你的朋友 – Bilawal 2014-10-29 13:01:00

+0

我正在嘗試它... – Bilawal 2014-10-29 13:01:56

0

克魯帕的帕特爾代碼是絕對細膩完美的作品,你做了什麼錯的是:

....空白屏幕沒有任何網格,對你的左下角方谷歌的標誌是指最有可能創建的API密鑰是不是一個合適的;你不應該創建其登記在谷歌開發者Console.The正確的鏈路驅動器您在谷歌地圖API的Android應用程序「啓用的API頁面」,這裏的鏈接https://console.developers.google.com/flows/enableapiapiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&reusekey=true