我實現了顯示地圖的應用程序。並使用經度和緯度顯示特定位置。但它顯示一個空的地圖,以查看地圖。請任何人都可以幫助我。 android-如何使用地圖查看地圖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>
請發佈您的main.xml .. –
我發佈了main.xml。請參考 – naresh
地圖api密鑰是由您的PC或任何其他PC生成的?我們的電腦只有 –