Android 地图未加载

Android 地图未加载,android,google-maps,Android,Google Maps,我有一个简单的应用程序,可以在地图上显示设备的位置。该应用程序似乎在地图未加载的情况下工作,而是在灰色网格中工作。我做了一些记录并查看了stacktrace。它提到MapActivity无法获取连接工厂客户端。 我已经看了好几条关于这个的线索,但我找不到答案 一旦应用程序运行,它只是在onDraw和onLocationChanged之间循环,无休止。我已经创建了一个MapView apiKey,并且正确的权限也在清单中。你知道我能做什么吗?谢谢 [编辑]我也在外面走来走去,因为大楼里没有gps:

我有一个简单的应用程序,可以在地图上显示设备的位置。该应用程序似乎在地图未加载的情况下工作,而是在灰色网格中工作。我做了一些记录并查看了stacktrace。它提到MapActivity无法获取连接工厂客户端。 我已经看了好几条关于这个的线索,但我找不到答案

一旦应用程序运行,它只是在onDraw和onLocationChanged之间循环,无休止。我已经创建了一个MapView apiKey,并且正确的权限也在清单中。你知道我能做什么吗?谢谢

[编辑]我也在外面走来走去,因为大楼里没有gps:)

[edit2]我还尝试重新生成不同的md5指纹以生成另一个apikey,但keytool生成相同的md5指纹。它已经存在了

[edit3]我还通过在keytool中使用不同的别名生成了不同的MD5指纹。这产生了一个不同的API密钥,不幸的是它仍然不能工作

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical" android:layout_width="match_parent" 
                android:layout_height="wrap_content" android:gravity="fill">
   <com.google.android.maps.MapView
        android:id="@+id/myGMap"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:enabled="true"
        android:clickable="true"
        android:apiKey="0??????syQI//C13Y-pRUNaA0a_??????pr86jE2w"
     />

   <EditText android:id="@+id/edittext1" 
             android:inputType="text"
             android:layout_width="fill_parent" 
             android:layout_height="wrap_content" 
             />

   <Button android:layout_height="wrap_content" 
          android:layout_width="wrap_content" 
          android:text="CLOSE"
          android:layout_alignParentRight="true"  
          android:id="@+id/close" ></Button> 

</RelativeLayout>

您是否获得了调试证书的api密钥?如果不是,那就是你的问题

试着读一读这篇文章,看看你们是如何做到这一点的

keytool -list -alias androiddebugkey -keystore "c:\Users\matt\debug.keystore" -storepass android -keypass android

嗨,是的,我想我都做到了。我遵循了下面的教程。没问题,像这样的事情会发生D
import java.util.List;

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.Overlay;


import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
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.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ZoomControls;

public class WcFinderActivity extends MapActivity implements LocationListener {
    /** Called when the activity is first created. */



    private MapView         gMapView        = null;
    private MapController   mc              = null;
    private Drawable        defaultMarker   = null;
    private GeoPoint        p               = null;
    private double          latitude        = 18.9599990845;
    private double          longitude = 72.819999694;
    private Context         mContext = this;

    private static final String TAG = "WcFinderActivity";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Log.e(TAG, "**********inside oncreate");

        EditText editText = (EditText)findViewById(R.id.edittext1);


        // Creating and initializing Map
        gMapView = (MapView) findViewById(R.id.myGMap);
        p = new GeoPoint((int) (latitude * 1000000), (int) (longitude * 1000000));
        gMapView.setSatellite(true);
        mc = gMapView.getController();
        mc.setCenter(p);
        mc.setZoom(14);

        // Add a location mark
        MyLocationOverlay myLocationOverlay = new MyLocationOverlay();
        List<Overlay> list = gMapView.getOverlays();
        list.add(myLocationOverlay);

        // Adding zoom controls to Map
        ZoomControls zoomControls = (ZoomControls) gMapView.getZoomControls();
        zoomControls.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));

        gMapView.addView(zoomControls);
        gMapView.displayZoomControls(true);

        // Getting locationManager and reflecting changes over map if distance travel by
        // user is greater than 500m from current location.
        Log.e(TAG, "**********about to call getSystemService");
        LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        Log.e(TAG, "**********about to call requestLocationUpdates");
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
        lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);



        Button close = (Button)findViewById(R.id.close);
        close.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Log.e(TAG,"clicked close");

            finish();

            }});

    }

    /* This method is called when use position will get changed */
    public void onLocationChanged(Location location) {
        if (location != null) {
            Log.e(TAG, "**********inside onLocationChanged");
            double lat = location.getLatitude();
            double lng = location.getLongitude();

            p = new GeoPoint((int) lat * 1000000, (int) lng * 1000000);
            mc.animateTo(p);
        }
    }

    public void onProviderDisabled(String provider) {
        // required for interface, not used

        Log.e(TAG, "**********inside onProviderDisabled");
    }

    public void onProviderEnabled(String provider) {
        // required for interface, not used
        Log.e(TAG, "**********inside onProviderEnabled");
    }

    public void onStatusChanged(String provider, int status, Bundle extras) {
        // required for interface, not used
        Log.e(TAG, "**********inside onStatusChanged");
    }

    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        Log.e(TAG, "**********inside isRouteDisplayed");
        return false;
    }

    /* User can zoom in/out using keys provided on keypad */
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_I) {
            gMapView.getController().setZoom(gMapView.getZoomLevel() + 1);
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_O) {
            gMapView.getController().setZoom(gMapView.getZoomLevel() - 1);
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_S) {
            gMapView.setSatellite(true);
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_T) {
            gMapView.setTraffic(true);
            return true;
        }
        return false;
    }

    /* Class overload draw method which actually plot a marker,text etc. on Map */
    protected class MyLocationOverlay extends com.google.android.maps.Overlay {

        @Override
        public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {

            super.draw(canvas, mapView, shadow);
            Paint paint = new Paint();
            Log.e(TAG, "**********inside onDraw");
            // Converts lat/lng-Point to OUR coordinates on the screen.
            Point myScreenCoords = new Point();
            mapView.getProjection().toPixels(p, myScreenCoords);

            paint.setStrokeWidth(1);
            paint.setARGB(255, 255, 255, 255);
            paint.setStyle(Paint.Style.STROKE);
            paint.setColor(Color.RED);


            canvas.drawCircle(myScreenCoords.x, myScreenCoords.y, 20, paint);
            canvas.drawText("I am here...", myScreenCoords.x, myScreenCoords.y, paint);
            return true;
        }
    }
}
01-19 16:13:59.698: D/ddm-heap(2294): Got feature list request
01-19 16:14:00.893: E/WcFinderActivity(2294): **********inside oncreate
01-19 16:14:01.073: E/WcFinderActivity(2294): **********about to call getSystemService
01-19 16:14:01.083: D/LocationManager(2294): Constructor: service = android.location.ILocationManager$Stub$Proxy@43cf74d8
01-19 16:14:01.083: E/WcFinderActivity(2294): **********about to call requestLocationUpdates
01-19 16:14:01.398: I/MapActivity(2294): Handling network change notification:CONNECTED
01-19 16:14:01.398: E/MapActivity(2294): Couldn't get connection factory client
01-19 16:14:01.438: E/WcFinderActivity(2294): **********inside isRouteDisplayed
01-19 16:14:01.613: D/dalvikvm(2294): GC freed 3423 objects / 218896 bytes in 81ms
01-19 16:14:02.003: D/dalvikvm(2294): GC freed 6408 objects / 380712 bytes in 87ms
01-19 16:14:02.283: E/WcFinderActivity(2294): **********inside onDraw
01-19 16:14:02.378: D/dalvikvm(2294): GC freed 10136 objects / 744376 bytes in 77ms
01-19 16:14:02.383: E/WcFinderActivity(2294): **********inside onDraw
01-19 16:14:02.423: E/WcFinderActivity(2294): **********inside onLocationChanged
01-19 16:14:02.448: E/WcFinderActivity(2294): **********inside onLocationChanged
01-19 16:14:02.493: E/WcFinderActivity(2294): **********inside isRouteDisplayed
01-19 16:14:02.523: E/WcFinderActivity(2294): **********inside onDraw
01-19 16:14:02.528: E/WcFinderActivity(2294): **********inside onDraw
01-19 16:14:02.578: E/WcFinderActivity(2294): **********inside isRouteDisplayed
01-19 16:14:02.603: E/WcFinderActivity(2294): **********inside onDraw
keytool -list -alias androiddebugkey -keystore "c:\Users\matt\debug.keystore" -storepass android -keypass android