2011-10-08 89 views
2

我已經爲谷歌地圖製作了一個應用程序。如何在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> 
+0

「無法顯示谷歌地圖」意味着任何錯誤或無法在地圖上顯示點?清除您的疑問 – Dharmendra

+0

它只是顯示點,但不顯示谷歌地圖。 – Jayesh

+1

可能是您沒有提供有效的地圖API密鑰。請檢查您的API密鑰。 – Dharmendra

回答

0

你的代碼看起來不錯。確保您在項目配置中選擇了「Google API」版本而不是Android版本作爲「項目構建目標」。

此外,您必須將以下行添加爲AndroidManifest中應用程序元素的子元素。

<uses-library android:name="com.google.android.maps"/> 

而這個作爲Manifest元素的孩子。

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

感謝您的回答,但我已經在清單文件中添加了這兩行。我仍然無法獲得谷歌地圖。 – Jayesh

+0

我得到了這個錯誤「無法獲得連接工廠客戶端 」在logcat中,這是什麼解決方案? – Jayesh

+0

聽起來像是API Key的問題。請查看[此鏈接](http://code.google.com/intl/es-ES/android/add-ons/google-apis/mapkey.html) – Oskarbi

0

「得到這個錯誤‘無法獲取連接工廠客戶端’在logcat中,究竟是什麼解決辦法嗎?」 .. Jayesh,這不是一個問題,因爲MapView的甚至每一次登錄此錯誤消息當它成功加載時。每次每次成功。 Jayesh,如果您在發佈應用程序中使用調試密鑰,通常會發生此問題。請注意,有兩個單獨的鍵 - 1用於調試,另一個用於發佈。這就是說,這個鍵是調試鍵還是釋放鍵?

相關問題