Android MapActivity googlemaps:无法获取连接工厂客户端

时间:2013-12-16 07:17:26

标签: java android google-maps mapactivity

我正在使用googlemaps V2,我已经制作了我的google api密钥V2。我第一次运行这个程序它的工作,然后当我再次运行它直到这一次,它总是无法显示地图,只有我给出的坐标。当我看到logcat时,错误是“无法获得连接工厂客户端”。当我打开我的map.xml图形布局时,会显示“当前主题中找不到样式'mapViewStyle'”。

任何人都可以帮我解决问题,以便程序可以显示地图吗?非常感谢你。

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>

3 个答案:

答案 0 :(得分:1)

如前所述,您使用来自API v1的对象和来自API V2的密钥。 因此,您不必像当前那样使用MapView,而是必须切换到MapFragmentSupportMapFragment(用于支持较旧的Android版本)。而不是MapActivity,您必须切换到FragmentActivity(如果您使用SupportMapFragment),或转换为简单Activity(如果您使用MapFragment

当然,正如所说的那样,密钥应该移到Manifest文件中,并且应该在那里定义一些额外的权限。

为了更好地了解您应该如何操作,您可以查看我在您的应用程序中集成Google Maps API V2时撰写的博文:

Google Maps API V2

答案 1 :(得分:0)

由于谷歌地图v1 API已经被删除,因此你将无法再使用它,你必须打开谷歌地图v2并需要根据v2 api开发地图。

在Google地图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

答案 2 :(得分:-1)

不是在布局文件中定义元数据键,而是在manifest.xml中声明它,如下所示。

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