0

我想在我的地图视图中显示 2 个地理点之间的路线,但是当我运行时,它总是在我的地图视图上显示一个白屏。我使用此链接中的示例作为参考

这是我的 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 权限。你们能帮我吗,告诉我上面的这些代码有什么问题。

4

1 回答 1

0

确保您拥有 MD5 指纹的密钥,因为现在 Google 会为 SHA1 指纹创建密钥,如果您将使用 SHA1 指纹创建的密钥与 MapView 一起使用,它将无法正常工作。

于 2013-01-09T09:31:22.150 回答