Android中的Google Map键?

时间:2012-04-06 05:18:42

标签: android google-maps

我正在开发一个Android应用程序,其中我必须显示地图视图我已经在之前的应用程序中完成了一次,但我之前使用的密钥不适用于他的应用程序。 它只是在应用程序中显示一个带空白屏幕的引脚。 我是否必须为每个项目使用不同的Map键,如果不是请帮助我如何使用我之前的Key。 而且我也尝试生成一个新密钥但是给了相同的密钥。

这是我使用的代码

  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;
        }

谢谢....

3 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:1)

Map Key仅限于单个机器,因为它包含Java库,JDK和all,因此debug.keystore也是一个文件,因此您将始终获得一个唯一的Map Key。

只有在移动机器(CPU)或重新安装操作系统时,才需要生成新的Map Key。

另一个建议是只删除Overlay代码并再次检查它是否正常工作。或者Overlay Class存在问题。清理并重建应用程序。

希望你也给了这些权限。

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

答案 2 :(得分:0)

您是否尝试在模拟器上运行该应用?如果是,那么使用默认密钥,如果您正在签出apk然后在设备上运行使用相同的密钥签名,就像您用于上一个应用程序并使用生成的谷歌地图api密钥。 你得到网格输出? 密钥或互联网的两个可能原因(互联网代理)