开发者

What is key store and how to implement google map

开发者 https://www.devze.com 2023-03-03 19:49 出处:网络
I want to show google map on my application which is running on emulator ...but which api key I had not work and in emulator only tiles are shown not map show. What to do for displaying map in my emul

I want to show google map on my application which is running on emulator ...but which api key I had not work and in emulator only tiles are shown not map show. What to do for displaying map in my emulator? I have read "getting MD5 Fingerprint" but not understood how to implement it.

My main.xml is:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<com.google.android.maps.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:enabled="true"
    android:apiKey="0mT--u1GbHdhnBJgPZU8zhoF2e4qdpCag32e7lQ"    />

</RelativeLayout>

and java file is:

package de.vogella.android.locationapi.maps;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener; 
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.RelativeLayout;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

public class ShowMap extends MapActivity {

    private MapController mapController;
    private MapView mapView;
    private LocationManager locationManager;

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.main); // bind the layout to the activity

        // create a map view
        RelativeLayout linearLayout = (RelativeLayout) findViewById(R.id.mainlayout);
        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        mapView.setStreetView(true);
        mapController = mapView.ge开发者_运维知识库tController();
        mapController.setZoom(14); // Zoon 1 is world view
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
                0, new GeoUpdateHandler());
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

    public class GeoUpdateHandler implements LocationListener {

        @Override
        public void onLocationChanged(Location location) {
            int lat = (int) (location.getLatitude() * 1E6);
            int lng = (int) (location.getLongitude() * 1E6);
            GeoPoint point = new GeoPoint(lat, lng);
            mapController.animateTo(point); //  mapController.setCenter(point);
        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    }
}


I had a problem when designing the NI Rail app that tiles would be displayed rather than actual map images. This seemed to be because I was using a debug keystore that the other guy on my team had created. Once we created a release keystore and a release api key the maps worked fine. Might be a similar problem for you.


First you need to get a MD5 fingerprint of your debug keystore. This is how to do it: http://code.google.com/intl/ru-RU/android/add-ons/google-apis/mapkey.html#getdebugfingerprint

Note, what if you are using release keystore and building app against it (i.e. using ant release) you need to get fingerprint for release keystore (but as you are sayng you are new to android i doubt you are using release keystore now)

Then you need to register key at Google and get Maps key. Follow this link: http://code.google.com/intl/ru-RU/android/add-ons/google-apis/mapkey.html#registering

Also, tell me please, where are you got your current maps key? If it is obtained as described above, maybe your app is missing of INTERNET permission in AndroidManifest.xml file.

Ensure you have the following line in your Manifest

<uses-permission android:name="android.permission.INTERNET" />
0

精彩评论

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