2013-12-16 73 views
0

我正在使用googlemaps V2,並且我已經創建了我的google api key V2。我第一次運行這個程序是工作,然後當我再次運行它時,它總是無法顯示地圖,只能協調我提供的地圖。當我看到logcat時,錯誤是「無法獲得連接工廠客戶端」。當我打開map.xml圖形佈局時,顯示「無法在當前主題中查找樣式'mapViewStyle'」。Android MapActivity googlemaps:無法獲取連接工廠客戶端

任何人都可以幫助我如何解決問題,讓程序可以顯示地圖?非常感謝。

enter image description here

enter image description here

人知道如何解決它?非常感謝。

這個我mapactivity

package unai.s1.skripsi.atm; 

import greendroid.widget.ActionBar; 
import greendroid.widget.ActionBar.Type; 

import java.util.List; 

import android.content.Context; 
import android.content.SharedPreferences; 
import android.graphics.drawable.Drawable; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.LinearLayout; 

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 com.google.android.maps.Overlay; 
import com.google.android.maps.OverlayItem; 
import unai.s1.skripsi.R; 
import unai.s1.skripsi.atm.TowerController; 
import unai.s1.skripsi.atm.TowerModel; 
import unai.s1.skripsi.atm.MapOverlay; 


public class Map extends MapActivity { 

private MapView mapView; 
private ActionBar actionBar; 
private MapController mapController; 
private GeoPoint gpUser, p; 
private SharedPreferences prefLocation; 

private Context mContext; 
String lat, lon, name, alamat; 
@Override 
protected void onCreate(Bundle bundle) { 
    super.onCreate(bundle); 
    setContentView(R.layout.map); 
    mContext = this; 

    actionBar = (ActionBar) findViewById(R.id.myActionBar); 
    actionBar.setTitle("Bandung Tour Guide"); 
    actionBar.setType(Type.Empty); 
    actionBar.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 

     } 
    }); 
    actionBar.getHandler(); 


    initMap(); 
} 

@SuppressWarnings("deprecation") 
public void initMap() { 
    mapView = (MapView) findViewById(R.id.map); 
    View zoomView = mapView.getZoomControls(); 
    LinearLayout myzoom = (LinearLayout) findViewById(R.id.zoom); 
    myzoom.addView(zoomView); 
    mapView.setStreetView(false); 
    mapView.setBuiltInZoomControls(true); 
    mapView.displayZoomControls(true); 
    // Untuk mengambil lokasi user saat ini 
    prefLocation = mContext.getSharedPreferences("mkul", 0); 
    double latUser = Double.parseDouble(prefLocation.getString("userLat", 
      "0")); 
    double lonUser = Double.parseDouble(prefLocation.getString("userLon", 
      "0")); 
    gpUser = new GeoPoint((int) (latUser * 1E6), (int) (lonUser * 1E6)); 

    mapController = mapView.getController(); 

    TowerController rc = new TowerController(mContext); 
    List<TowerModel> lsRm = rc.getAll(); 

    for (int i = 0; i < lsRm.size(); i++) { 
     TowerModel poi = lsRm.get(i); 

     lat = poi.getLat(); 
     lon = poi.getLon(); 
     name = poi.getName(); 
     alamat = poi.getAddress(); 

     String coordinates[] = {lat, lon}; 

     double lati = Double.parseDouble(coordinates[0]); 
     double longi = Double.parseDouble(coordinates[1]); 

     p = new GeoPoint((int) (lati * 1E6), (int) (longi * 1E6)); 

     List<Overlay> mapOverlays = mapView.getOverlays(); 
     int draw = R.drawable.marker; 
     Drawable drawable = this.getResources().getDrawable(draw); 
     MapOverlay itemizedoverlay = new MapOverlay(drawable,mContext,poi); 
     OverlayItem overlayitem = new OverlayItem(p, name, alamat); 
     itemizedoverlay.addOverlay(overlayitem); 
     mapOverlays.add(itemizedoverlay); 
    } 
    mapController.animateTo(gpUser); 
    mapController.setZoom(16); 
} 

@Override 
protected boolean isRouteDisplayed() { 
    // TODO Auto-generated method stub 
    return false; 
} 

} 

這是我map.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<greendroid.widget.ActionBar 
    android:id="@+id/myActionBar" 
    android:layout_width="fill_parent" 
    android:layout_height="30dp" 
    android:background="@drawable/action_bar_background" /> 

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <com.google.android.maps.MapView 
     android:id="@+id/map" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:apiKey="AIzaSyAT5pGvWOLeEuugI8asdasE7as3osTaZjSQ" 
     android:clickable="true" 
     android:enabled="true" 
     /> 

    <LinearLayout 
     android:id="@+id/zoom" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" /> 
</RelativeLayout> 

</LinearLayout> 

這是我androidmanifest

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

<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="17" /> 

<application 

    android:icon="@drawable/bc1" 
    android:label="@string/app_name" 
    android:name=".hotel.mmMtowerApplication" 
    android:theme="@style/Theme.coba" > 

    <activity 
     android:label="@string/app_name" 
     android:name=".hotel.DashboardActivity" 
     android:screenOrientation="portrait" > 
     <intent-filter > 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

     <!-- Login Activity --> 
    <activity 
     android:label="Login Account" 
     android:name=".login.LoginActivity"></activity> 

    <!-- Register Activity --> 
    <activity 
     android:label="Register New Account" 
     android:name=".login.RegisterActivity"></activity> 


    <activity 
     android:name=".hotel.MTowerOpening" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".rs.MhotelOpening" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".polisi.MpolisiOpening" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".kuliner.MkulinerOpening" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".wisata.MwisataOpening" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".fo.MfoOpening" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".atm.MatmOpening" 
     android:screenOrientation="portrait" > 
    </activity> 



    <activity 
     android:name=".hotel.MTowerActivity" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".rs.Rsactivity" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".polisi.Polisiactivity" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".kuliner.Kulineractivity" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".wisata.Wisataactivity" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".fo.Foactivity" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".atm.Atmactivity" 
     android:screenOrientation="portrait" > 
    </activity> 



    <activity 
     android:name=".hotel.Underconstructions" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".rs.Underconstructions" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".polisi.Underconstructions" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".kuliner.Underconstructions" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".wisata.Underconstructions" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".fo.Underconstructions" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".atm.Underconstructions" 
     android:screenOrientation="portrait" > 
    </activity> 


    <activity 
     android:name=".hotel.Tower" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".rs.Tower" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".polisi.Tower" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".kuliner.Tower" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".wisata.Tower" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".fo.Tower" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".atm.Tower" 
     android:screenOrientation="portrait" > 
    </activity> 




    <activity 
     android:name=".hotel.TowerDetailInformation" 
     android:screenOrientation="portrait" 
     android:label="@string/app_name" > 
    </activity> 
    <activity 
     android:name=".rs.TowerDetailInformation" 
     android:screenOrientation="portrait" 
     android:label="@string/app_name" > 
    </activity> 
    <activity 
     android:name=".polisi.TowerDetailInformation" 
     android:screenOrientation="portrait" 
     android:label="@string/app_name" > 
    </activity> 
    <activity 
     android:name=".kuliner.TowerDetailInformation" 
     android:screenOrientation="portrait" 
     android:label="@string/app_name" > 
    </activity> 
    <activity 
     android:name=".wisata.TowerDetailInformation" 
     android:screenOrientation="portrait" 
     android:label="@string/app_name" > 
    </activity> 
    <activity 
     android:name=".fo.TowerDetailInformation" 
     android:screenOrientation="portrait" 
     android:label="@string/app_name" > 
    </activity> 
    <activity 
     android:name=".atm.TowerDetailInformation" 
     android:screenOrientation="portrait" 
     android:label="@string/app_name" > 
    </activity> 




    <activity 
     android:name=".hotel.About" 
     android:screenOrientation="portrait" 
     android:label="about aplikasi" > 
    </activity> 
    <activity 
     android:name=".rs.About" 
     android:screenOrientation="portrait" 
     android:label="about aplikasi" > 
    </activity> 
    <activity 
     android:name=".polisi.About" 
     android:screenOrientation="portrait" 
     android:label="about aplikasi" > 
    </activity> 
    <activity 
     android:name=".kuliner.About" 
     android:screenOrientation="portrait" 
     android:label="about aplikasi" > 
    </activity> 
    <activity 
     android:name=".wisata.About" 
     android:screenOrientation="portrait" 
     android:label="about aplikasi" > 
    </activity> 
    <activity 
     android:name=".fo.About" 
     android:screenOrientation="portrait" 
     android:label="about aplikasi" > 
    </activity> 
    <activity 
     android:name=".atm.About" 
     android:screenOrientation="portrait" 
     android:label="about aplikasi" > 
    </activity> 




    <activity 
     android:name=".hotel.MapRoute" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".rs.MapRoute" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".polisi.MapRoute" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".kuliner.MapRoute" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".wisata.MapRoute" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".fo.MapRoute" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".atm.MapRoute" 
     android:screenOrientation="portrait" > 
    </activity> 




    <activity 
     android:name=".hotel.Map" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".rs.Map" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".polisi.Map" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".kuliner.Map" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".wisata.Map" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".fo.Map" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".atm.Map" 
     android:screenOrientation="portrait" > 
    </activity> 




    <activity 
     android:name=".hotel.MapDetail" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".rs.MapDetail" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".polisi.MapDetail" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".kuliner.MapDetail" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".wisata.MapDetail" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".fo.MapDetail" 
     android:screenOrientation="portrait" > 
    </activity> 
    <activity 
     android:name=".atm.MapDetail" 
     android:screenOrientation="portrait" > 
    </activity> 
<uses-library android:name="com.google.android.maps" /> 
</application> 

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.ACCESS_LOCATION" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.CALL_PHONE" > 
</uses-permission> 
</manifest> 

回答

0

由於谷歌地圖1.0版API已depricated,所以你將不再能夠使用它,你必須打開谷歌地圖V2並需要根據V2 API來開發地圖。

在谷歌地圖V2在佈局中的地圖使用,如下所述片段充氣:

因此,而不是這個谷歌地圖

<com.google.android.maps.MapView 
    android:id="@+id/map" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:apiKey="AIzaSyAT5pGvWOLeEuugI8asdasE7as3osTaZjSQ" 
    android:clickable="true" 
    android:enabled="true" 
    /> 

嘗試如下:

<?xml version="1.0" encoding="utf-8"?> 
<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/map" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:name="com.google.android.gms.maps.MapFragment"/> 

對於更多詳情退房執行HERE

-1

取代在佈局文件中定義元數據鍵,按如下所示在manifest.xml中聲明它。

<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyAT5pGvWOLeEuugI8asdasE7as3osTaZjSQ" />

+0

通過這樣做,它會導致出現異常。 '11-04 10:35:11.806:E/AndroidRuntime(30283):導致:java.lang.IllegalArgumentException:您需要爲每個MapView指定一個API密鑰。 # –

1

正如已經說過,你正在使用的對象從API v1API V2的關鍵。 因此,您不必像現在一樣使用MapView,而必須切換到MapFragmentSupportMapFragment(用於支持較舊的Android版本)。相反,在MapActivity你將不得不(如果你使用SupportMapFragment)切換到FragmentActivity,或者一個簡單的Activity(您使用MapFragment萬一)爲說,關鍵要移到清單文件

當然,還有一些應該在那裏定義額外的權限。

要得到你應如何做一個更好的主意,你可以檢查這個博客文章中,我在您的應用程序集成Google Maps API V2寫道:

Google Maps API V2

+0

非常感謝你@EmilAdz 這意味着我必須再次將google-play-services_lib導入到我的項目中,因爲我已經將外部jar添加到了我的項目maps.jar中。我也使用greendroid庫。 –

+0

和我使用2.2(froyo),我必須使用谷歌播放服務proyo或沒有froyo?因爲有兩個選項谷歌播放服務froyo和谷歌播放服務@EmilAdz –

+0

如果您按照博客文章中的指南的所有步驟,最終應該收到一張地圖,如果它是froyo或不是相關的。關於google-play-service lib,我建議你使用SDK Manager重新下載最新版本,並從你的項目屬性再次引用它。 –

相關問題