2011-11-01 28 views
0

我實現了顯示地圖的應用程序。並使用經度和緯度顯示特定位置。但它顯示一個空的地圖,以查看地圖。請任何人都可以幫助我。 enter image description hereandroid-如何使用地圖查看地圖lib

code 

公共類mapsdemo擴展MapActivity {

MapView mapView; 
GeoPoint gp; 
MapController mc; 

/** Called when the activity is first created. */ 
@SuppressWarnings({ "unchecked", "rawtypes" }) 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

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

    List mapOverlays = mapView.getOverlays(); 
    Drawable drawable = this.getResources().getDrawable(R.drawable.icon); 
    HelloItemizedOverlay itemizedOverlay = new HelloItemizedOverlay(drawable, this); 

    double lat = 17.385044; 
    double longi = 78.486671; 

    gp = new GeoPoint((int) (lat *1E6),(int) (longi *1E6)); 
    OverlayItem overlayitem = new OverlayItem(gp, "Hello", "I'm in Hyd");                  
    itemizedOverlay.addOverlay(overlayitem);   
    mapOverlays.add(itemizedOverlay); 

    mc = mapView.getController(); 
    mc.animateTo(gp); 
    mc.setZoom(13); 
} 

@Override 
protected boolean isRouteDisplayed() {  
    return false; 
} 

}

main.xml 
< ?xml version="1.0" encoding="utf-8"?> 

< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 

< com.google.android.maps.MapView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:apiKey="00YCOT71Vu0btHPPlbIR9uvF0-l4mcAVT9_6HMw" 
       android:id="@+id/mapView" 
       android:enabled="true" 
       android:clickable="true"   
       /> 
< /LinearLayout> 

manifeast 

<?xml version="1.0" encoding="utf-8"?> 

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.maps.demo" 
     android:versionCode="1" 
     android:versionName="1.0"> 

    < uses-sdk android:minSdkVersion="7" /> 

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

    <application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <activity android:name=".mapsdemo" 
        android:label="@string/app_name" 
        android:theme="@android:style/Theme.NoTitleBar"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <uses-library android:name="com.google.android.maps" /> 
    </application> 
</manifest> 
+1

請發佈您的main.xml .. –

+0

我發佈了main.xml。請參考 – naresh

+0

地圖api密鑰是由您的PC或任何其他PC生成的?我們的電腦只有 –

回答

0

這很可能是由於簽名不匹配造成的。請確保您註冊了用於將您的應用程序與Google打包在maps API signup page的密鑰庫中的私鑰,並確保發佈的密鑰位於MapView的佈局文件中。

+0

如何獲得正確的簽名? – naresh

+0

我在答案中鏈接的maps api註冊頁面顯示用於獲取您的私鑰的MD5指紋的keytool命令。只要確保你使用的是正確的密鑰倉庫(如果你使用eclipse android插件並且沒有改變任何默認設置,它就會在你的home文件夾的.android目錄中)。 – Chris

相關問題