Robi Kumar Tomar
Robi Kumar Tomar

Reputation: 3404

Android: not getting proper google map only getting map icon on device

I have developed a app in which i want to use the Google Map to show the location view,I have found many useful concepts from stack overflow and Google also,And successfully implemented my App by following these all.My App is running without any bug but not showing proper Map.

output that i am getting:

enter image description here

Here is my Java File:

    package com.mapactivity;

import java.util.List;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.KeyEvent;

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

public class MainActivity extends MapActivity implements LocationListener{

    MapView mapView;
    MapController mc;
    GeoPoint gp;
    MyLocationOverlay compass;
    long start;
    long stop;

    Drawable d;
    List<Overlay> overlayList;
    LocationManager lm;
    String towers;
    /*int lat;
    int longi;*/

    int x,y;

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

        mapView = (MapView) findViewById(R.id.mapView);

        mapView.setTraffic(true);
        mapView.setBuiltInZoomControls(true);
        mapView.setSatellite(true);


        mc = mapView.getController();

        String cordinate[] = {"28.636041","77.223957"};

        double lat = Double.parseDouble(cordinate[0]);
        double lng = Double.parseDouble(cordinate[1]);

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

        mc.animateTo(gp);
        mc.setZoom(13);


        MapOverlay mo = new MapOverlay();
        List<Overlay> list = mapView.getOverlays();
        list.clear();
        list.add(mo);

        mapView.invalidate();


    }

    public boolean onKeyDown(int keyCode,KeyEvent event)
    {
        mc = mapView.getController();
        switch (keyCode) {
        case KeyEvent.KEYCODE_3:
            mc.zoomIn();

            break;

        case KeyEvent.KEYCODE_1:
            mc.zoomOut();
        }
        return super.onKeyDown(keyCode, event);

    }
    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
    private class MapOverlay extends com.google.android.maps.Overlay
    {

        @Override
        public boolean draw(Canvas canvas, MapView mapview, boolean shadow, long when) {
            // TODO Auto-generated method stub
            super.draw(canvas, mapview, shadow);

            Point screenPoint = new Point();
            mapview.getProjection().toPixels(gp, screenPoint);
            Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.marker_landmark);
            canvas.drawBitmap(bmp, screenPoint.x, screenPoint.y-50,null);

            return true;

        }

    }

    @Override
    public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }

}

And i have given all permissions in manifest file also but not getting the right things,Please let me know where i am doing wrong.

Upvotes: 0

Views: 260

Answers (4)

Emil Adz
Emil Adz

Reputation: 41119

You should move your map implementation to API V2 instead of API V1, because as been already said here the API version is deprecated, which means that you can no longer produce an API Key for this version. My quess would be that you have a key for V2 and you are trying to use it with V1 implementation.

To move your code to API V2 implementation please follow the following blog post I wrote on this matter:

Google Maps API V2

Upvotes: 0

AnniJais
AnniJais

Reputation: 2780

Google Map V1 API Documentation says that:

Version 1 of the Google Maps Android API has been officially deprecated as of December 3rd, 2012. This means that from March 18th, 2013 you will no longer be able to request an API key for this version. No new features will be added to Google Maps Android API v1. However, apps using v1 will continue to work on devices. Existing and new developers are encouraged to use Google Maps Android API v2.

Now only those applications will work fine with old Google MAP API's whose keys were generated before March 18, 2013.

Since you're developing an app now using the old depreciated API, I guess you have generated the API key for newer version but you're trying to use it with the old API implementation. The new API keys will not work with old API.

Recommended to use Google Map V2 for new applications.

Upvotes: 0

Shadow
Shadow

Reputation: 6899

Use V2. Google map v1 has been deprecated and key been no longer maintained on Feb-March 2013 itself

and for google map v2, you have two keys. Debug and release key. Debug key is common.But when you use signed apk, use release key or else map looks blank.

For release key procedure is here.

Google Map Android API v2 can't display map in play store application

Upvotes: 0

Jitesh Dalsaniya
Jitesh Dalsaniya

Reputation: 1917

See code from given link. May it helps you.

Upvotes: 1

Related Questions