我正在使用googlemaps V2,並且我已經創建了我的google api key V2。我第一次運行這個程序是工作,然後當我再次運行它時,它總是無法顯示地圖,只能協調我提供的地圖。當我看到logcat時,錯誤是「無法獲得連接工廠客戶端」。當我打開map.xml圖形佈局時,顯示「無法在當前主題中查找樣式'mapViewStyle'」。Android MapActivity googlemaps:無法獲取連接工廠客戶端
任何人都可以幫助我如何解決問題,讓程序可以顯示地圖?非常感謝。
人知道如何解決它?非常感謝。
這個我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>
通過這樣做,它會導致出現異常。 '11-04 10:35:11.806:E/AndroidRuntime(30283):導致:java.lang.IllegalArgumentException:您需要爲每個MapView指定一個API密鑰。 # –