android-如何使用maps lib查看地图

时间:2011-11-01 13:23:31

标签: android maps

我实现了显示地图的应用。它使用纬度和经度显示特定位置。但它显示一个空的map.how来查看地图。请任何人帮助我。 enter image description here

code

public class 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 个答案:

答案 0 :(得分:0)

这很可能是由签名不匹配引起的。确保您在用于将应用程序打包到maps API signup page的Google的密钥库中注册了私钥,并确保发布的密钥位于MapView的布局文件中。