【问题标题】:Google Map key in Android?Android中的谷歌地图键?
【发布时间】:2012-04-06 05:18:41
【问题描述】:

我正在开发一个 android 应用程序,我必须在其中显示地图视图,我在以前的应用程序中做过一次,但我在以前的应用程序中使用的密钥在他的应用程序中不起作用。 它只是在应用程序中显示一个带有空白屏幕的引脚。 我是否必须为每个项目使用不同的 Map 密钥,如果不是,请帮助我如何使用我以前的密钥。 我也尝试生成一个新密钥,但返回了相同的密钥。

这是我使用的代码

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

谢谢……

【问题讨论】:

    标签: android google-maps


    【解决方案1】:
    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

    【讨论】:

    • 地图未显示的一个原因可能是您正在使用发布密钥进行开发,将其替换为您的调试密钥
    【解决方案2】:

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

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

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

    希望您也授予这些权限。

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

    【讨论】:

      【解决方案3】:

      您是否尝试在模拟器上运行该应用程序?如果是,则使用默认密钥,如果您要退出 apk,然后在设备上运行,则使用与上一个应用程序相同的密钥进行签名,并使用生成的 google map api 密钥。 您是否将网格作为输出? 密钥或互联网(代理互联网)的两个可能原因

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-08-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-12-31
        • 2012-11-27
        相关资源
        最近更新 更多