我已經爲谷歌地圖製作了一個應用程序。如何在android中製作Google地圖?
我使用經度和緯度作爲位置。 但我無法顯示谷歌地圖,
有人能幫助我,什麼是錯我的代碼,
代碼如下:
package com.googlemaps;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import android.app.Activity;
import android.os.Bundle;
public class GooglemapsActivity extends MapActivity{
/** Called when the activity is first created. */
MapController mControl;
GeoPoint GeoP;
MapView mapV;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapV = (MapView) findViewById(R.id.mapView);
mapV.displayZoomControls(true);
mapV.setBuiltInZoomControls(true);
double lat = 40.8;
double longi = 96.666;
GeoP = new GeoPoint((int)(lat * 1E6), (int) (longi * 1E6));
mControl = mapV.getController();
mControl.animateTo(GeoP);
mControl.setZoom(13);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
和XML文件是:
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:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0acFPt8mdFAjqGq9AuToZIgkd4b8jxUM0K8mg0Q"
/>
</LinearLayout>
「無法顯示谷歌地圖」意味着任何錯誤或無法在地圖上顯示點?清除您的疑問 – Dharmendra
它只是顯示點,但不顯示谷歌地圖。 – Jayesh
可能是您沒有提供有效的地圖API密鑰。請檢查您的API密鑰。 – Dharmendra