开发者

how to get google api key for device [duplicate]

This question already has an answer here: Map display with release key in android (1 answer) Closed last month.

I have created an application in Android based on Google Maps. I got an API key and it's running successfully in the emulator but when I run it on a device, it's showing a force close message. Can someone please explain how to get an API key for use on a device and whether I have to get an API key specifically for device use at all?

My Java code:

setContentView(R.layout.mapview);
mapView = (MapView) findViewById(R.id.mapview);       
mapView.setBuiltInZoomControls(true);

String coordinates[] = {"9.966667", "78.166667"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
GeoPoint  p = new GeoPoint((int) (lat * 1E6),(int) (lng * 1E6));

MapController mapController = mapView.getController();

mapController.setCenter(p);
mapController.animateTo(p);
mapController.setZoom(12);

My layout:

<Lin开发者_Go百科earLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" >

    <com.google.android.maps.MapView
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:enabled="true"
        android:clickable="true"
        android:apiKey="myapikey" />

</LinearLayout>

Logcat error:

 Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x1080215

This issue is a blocker on my project so I cannot move forward until it is fixed.


Read the documentation

edit: okay I'm quoting the documentation for you

When you are preparing to release your application, however, note that you must sign your application with a suitable cryptographic key, rather than the SDK debug key. That means that you will also need to register your application's release certificate with the Google Maps service. After you've done so, you will receive a new Maps API Key that is uniquely associated with your release certificate. To enable the MapView elements in your application to work after release, you must remember to change the Maps API Key for all MapViews in your application so that they refer to the Key associated with your release certificate (rather than your debug certificate).

Fine read the following section "Getting the MD5 Fingerprint of Your Signing Certificate"

$ keytool -list -alias alias_name -keystore my-release-key.keystore
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜