Amandeep singh
Amandeep singh

Reputation: 1883

Google Map key in Android?

I am developing an android app in which i have to show map view i have done it once in a previous app but the key i used in the previous is not working int his app . It is just showing a pin in the application with blank screen. Do i have to use a different Map key for each project , If not Kindly help me how can i use my previous Key in this. and also I tried generating a new key but gave the the same key back .

Here is the code i used

  public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map);
        btn=(Button)findViewById(R.id.mapbtn);
        str1=getIntent().getStringExtra("LATITUDE");
        str2=getIntent().getStringExtra("LONGITUDE");





        mapView =  (MapView)findViewById(R.id.mapView1);
        //View zoomView = mapView.getZoomControls(); 

        mapView.setBuiltInZoomControls(true);
         //mapView.setSatellite(true);
         mc = mapView.getController();
         btn.setOnClickListener(this);

          MapOverlay mapOverlay = new MapOverlay();
            List<Overlay> listOfOverlays = mapView.getOverlays();
            listOfOverlays.clear();
            listOfOverlays.add(mapOverlay); 


            String coordinates[] = {str1,  str2};
            double lat = Double.parseDouble(coordinates[0]);
            double lng = Double.parseDouble(coordinates[1]);

            p = new GeoPoint(
                (int) (lat * 1E6), 
                (int) (lng * 1E6));

            mc.animateTo(p);
            mc.setZoom(17); 
            mapView.invalidate();

        //mp.equals(o);
    }
    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
    class MapOverlay extends com.google.android.maps.Overlay
    {
        @Override
        public boolean draw(Canvas canvas, MapView mapView, 
        boolean shadow, long when) 
        {
            super.draw(canvas, mapView, shadow);                   
            Paint mPaint = new Paint();
            mPaint.setDither(true);
            mPaint.setColor(Color.RED);
            mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
            mPaint.setStrokeJoin(Paint.Join.ROUND);
            mPaint.setStrokeCap(Paint.Cap.ROUND);
            mPaint.setStrokeWidth(2);

            //---translate the GeoPoint to screen pixels---
            Point screenPts = new Point();
            mapView.getProjection().toPixels(p, screenPts);

            //---add the marker---
            Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.pin);            
            canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);         
            return true;
        }

Thanks....

Upvotes: 0

Views: 636

Answers (3)

vipin
vipin

Reputation: 3001

amandeep there are two kinds of key for maps debug key and release key 
debug key is for your system on which you are developping your application 
that can be used for every application and the seconde one is release key that is different for every application and for each application you have to create new one

http://code.google.com/android/add-ons/google-apis/mapkey.html

Difference between Debug and Signing key

Upvotes: 3

Sunny Kumar Aditya
Sunny Kumar Aditya

Reputation: 2846

Are you trying to run the app on emulator? if yes Then use the default key , I f you are signing out the apk then running on a device use the same key to sign as you used for the last app and use the generated google map api key . Are you getting grids as output ?? Two possible reasons key or internet(internet over proxy)

Upvotes: 0

Bhavin
Bhavin

Reputation: 6010

Map Key is Only restricted to a Single Machine as it includes Java libraries, JDK and all, so debug.keystore is also a single file and by this you will always get a UNIQUE Map Key.

You will have to Generatea new Map Key only when you Shift your Machine(CPU) or reinstall your OS.

Another advice to Just remove code of Overlay and just Check it again is it working fine. Or there is a problem in Overlay Class. Clean and Rebuild the Application.

Hope you have given these permissions also.

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

Upvotes: 1

Related Questions