2012-12-31 5 views
0

내지도보기에서 2 geopoint 사이의 경로를 표시하고 싶지만 실행하면 내지도보기에 흰색 화면이 표시됩니다. 내 참조mapView에 흰색 화면 표시

여기 내 MapActivity 클래스의이 link의 예를 사용합니다

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" 
/> 

그리고 이미 인터넷, ACCESS_FINE_LOCATION를 사용, ACCESS_COARSE_LOCATION 권한 u 남자들이 나를 도와 줄 수있어, 위의 코드가 잘못된 부분을 말해줘.

+1

Android Manifestfile에지도 라이브러리 태그를 추가 했습니까? – DynamicMind

+0

나는 벌써 그랬다 – user1849289

+0

마녀 api 열쇠는 당신이 debug.keystore를 사용하여 r인가? – Youddh

답변

0

요즘 Google은 SHA1 지문에 대한 키를 만들기 때문에 MD5 지문 용 키가 있는지 확인하고 MapView에서 SHA1 지문으로 만든 키를 사용하면 작동하지 않을 수 있습니다.