谷歌地图没有显示在Android(签名的apk)与谷歌V2发布密钥

时间:2013-06-21 09:41:15

标签: android google-maps signed

我正在关注步骤Given here。 通过以下步骤Here获取API密钥 我已经上市了apk用于测试目的,但它仍然没有显示地图,虽然它显示地图与调试键。但是当我尝试使用发布谷歌地图键时,它显示白色屏幕与zoomin和zoomout按钮但没有地图。

Google play store link

MapFragment

public class CustomMap extends SupportMapFragment {

private static final int ZOOMIN_ANIMATION_DURATION = 300;

public static CustomMap newInstance() {
    Bundle bundle = new Bundle();
    CustomMap customMap = new CustomMap();
    customMap.setArguments(bundle);
    return customMap;

}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

}

@Override
public void onResume() {
    super.onResume();
    GoogleMap googleMap = getMap();
    if (googleMap == null) {
    } else {
        LatLng mLatLng = new LatLng(70.00,
                33.00);

        googleMap.addMarker(new MarkerOptions()
                .title("Title")
                .snippet("Address")
                .position(mLatLng)
                .icon(BitmapDescriptorFactory
                        .fromResource(R.drawable.ic_launcher)));
        googleMap.moveCamera(CameraUpdateFactory.newLatLng(mLatLng));
        googleMap.animateCamera(CameraUpdateFactory.zoomBy(10),
                ZOOMIN_ANIMATION_DURATION, null);
    }
}

}

主要活动

public class MainActivity extends FragmentActivity {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<fragment
    android:id="@+id/fragment1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    class="com.example.maptest.CustomMap" 
  />

</RelativeLayout>

清单          

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

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

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" >
</uses-permission>
<uses-permission android:name="com.baresso.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"   />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.maptest.MainActivity"
        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.maps.v2.API_KEY"
        android:value="AIzaSyDcAy3bEVhv_lhAH1hHNHk_RpvyXiN0xNI" />
</application>

</manifest>

4 个答案:

答案 0 :(得分:2)

https://developers.google.com/maps/documentation/android/start

  
      
  1. 我认为问题在于获取API密钥或使用SHA-1指纹。
  2.   
  3. 让你给应用程序包中的SHA-1指纹   Google Consol
  4.   
  5. 将Google Play服务安装到您的模拟器或Android设备中。
  6.   
  7. 请选择Android设备进行地图测试。
  8.   

答案 1 :(得分:1)

Google地图无法使用其政策中的最新更改,这些更改会直接限制Google地图库的使用。

要解决此问题,您必须将整个谷歌地图作为第三方插件包含在内,或者您可以在网页浏览中显示谷歌地图并通过javascript html函数传递位置。

代表: -

<script>
function initialize()
{
document.getElementById('dummyDIV').innerHTML = '<div id="googleMap"     
style="width:'+screen.width+'px;height:'+screen.height+'px;"></div>';
var sURL1 = window.document.URL;
var sURL2 =sURL1.split("%20");
var sURL= sURL2[0];
for (j=1;j<sURL2.length;j++){
    sURL = sURL+' '+sURL2[j];
} 

var mapProp = {
  center:new google.maps.LatLng(19.155721,72.856025),
  zoom:10,
  disableDefaultUI:true, 
  zoomControl:true,
  mapTypeControl:true,
  mapTypeId:google.maps.MapTypeId.ROADMAP

  };

var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);


   if (sURL.indexOf("?") > 0)
{
var bifurcatedURL = sURL.split("?");    

var everyMarker = bifurcatedURL[1].split("&");  
for (i=0;i<everyMarker.length;i++)
    {
        var markerDetails =everyMarker[i].split("+");
        var lat = (markerDetails[0]);
        var lon = (markerDetails[1]);
        var address =markerDetails[2];
        var type = markerDetails[3];
        var markerPosition = new google.maps.LatLng(lat,lon);
        map.setCenter(markerPosition);
        if(type=='a'||type=='A')
    var marker=new 
google.maps.Marker({position:markerPosition,icon:'atm_marker.png'});
        else if(type=='b'||type=='B')
 var marker=new google.maps.Marker
 ({position:markerPosition,icon:'branch_marker.png'});
        else if(type=='c'||type=='C')
var marker=new google.maps.Marker({position:markerPosition,icon:'pin_blue.png'});

            marker.setMap(map);
    var infowindow = new             google.maps.InfoWindow({content:address});
            listenMarker(marker,address,infowindow,map)
    }
}   
}

function listenMarker (marker,address,infowindow,map)
{
// so marker is associated with the closure created for the listenMarker function call
google.maps.event.addListener(marker, 'click', function() {
                    infowindow.open(map, marker);
                });
}

 google.maps.event.addDomListener(window, 'load', initialize);
</script>

答案 2 :(得分:0)

问题就在这里

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

用给出你自己的包名替换它..

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

,此处

替换此

<uses-permission android:name="com.baresso.permission.MAPS_RECEIVE" />
with <uses-permission android:name="com.example.maptest.permission.MAPS_RECEIVE" />  

答案 3 :(得分:0)

当您点击完成后点击apk后,从logcat复制SHA1并将其添加到您的google play开发者控制台项目SHA-1证书指纹这将显示您的地图与signeg apk