mapView显示白色屏幕

时间:2012-12-31 11:51:25

标签: android google-maps android-mapview driving-directions

我想在我的mapview中显示2个geopoint之间的路线,但是当我跑步时,它会在我的mapview上显示一个白色的屏幕。我使用此link中的示例作为参考

这是我的MapActivity类:

public class M_hospital_map extends MapActivity {

 // Map view
 MapView mapView = null;

 GeoPoint geoPoint;
 GeoPoint dest_geoPoint;

 // Progress dialog
 ProgressDialog pDialog;

 // Map controllers
 MapController mapController;

 GeoPoint start, dest;

 double latitude;
 double longitude;
 double dest_latitude;
 double dest_longitude;

 OverlayItem overlayitem;

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

    // Getting intent data
    Intent i = getIntent();

    Bundle bundle = i.getExtras();

    // get all data from bundle
    double user_latitude = bundle.getDouble("user_latitude");
    double user_longitude = bundle.getDouble("user_longitude");
    double dest_latitude = bundle.getDouble("dest_latitude");
    double dest_longitude = bundle.getDouble("dest_longitude");


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



    DirectionsTask getDirectionsTask = new DirectionsTask();
    getDirectionsTask.execute(new GeoPoint((int)(user_latitude * 1E6),(int)(user_longitude * 1E6)),
                  new GeoPoint((int)(dest_latitude * 1E6),(int)(dest_longitude * 1E6)));

 }

 private class DirectionsTask extends AsyncTask<GeoPoint, Void, Route> {

    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(M_hospital_map.this);
        pDialog.setMessage(Html.fromHtml("<b>Google Map</b><br/>Loading Route..."));
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        pDialog.show();
    }

        protected Route doInBackground(GeoPoint...geoPoints) {
            start = geoPoints[0];
            dest =  geoPoints[1];

                Parser parser;
                String jsonURL = "http://maps.google.com/maps/api/directions/json?";
                final StringBuffer sBuf = new StringBuffer(jsonURL);
                sBuf.append("origin=");
                sBuf.append(start.getLatitudeE6()/1E6);
                sBuf.append(',');
                sBuf.append(start.getLongitudeE6()/1E6);
                sBuf.append("&destination=");
                sBuf.append(dest.getLatitudeE6()/1E6);
                sBuf.append(',');
                sBuf.append(dest.getLongitudeE6()/1E6);
                sBuf.append("&sensor=true&mode=driving");
                Log.v("URL", sBuf.toString());

                parser = new GoogleParser(sBuf.toString());
                Route r =  parser.parse();
                return r;
        }

    protected void onPostExecute(Route route) {
        pDialog.dismiss();
        RouteOverlay routeOverlay = new RouteOverlay(route, Color.BLUE);
        mapView.getOverlays().add(routeOverlay);
        mapView.invalidate();
        mapController = mapView.getController();
        mapController.setZoom(16);
        mapView.getMapCenter();
    }
 }

 @Override
 protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
 }
}

我的m_hospital_map.xml是这样的:

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="0WM32EymVRmIVGz-fKJhPs2BT_sH1CZtV3QG54w"
/>

我已经使用了INTERNET,ACCESS_FINE_LOCATION,ACCESS_COARSE_LOCATION权限。你们可以帮助我,告诉我上面这些代码有什么问题。

1 个答案:

答案 0 :(得分:0)

确保您拥有MD5指纹的密钥,因为现在Google为SHA1指纹创建了密钥,如果您使用使用SHA1指纹创建的密钥与MapView一起使用它。