1
 public class MyPositionActivity extends MapActivity{
 @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_position);
    linearLayout = (LinearLayout) findViewById(R.id.zoomview);
    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

    mapView.setTraffic(true);
    mZoom = (ZoomControls) mapView.getZoomControls();
    linearLayout.addView(mZoom);            
    MapController controller = mapView.getController();     
    GeoPoint point = locate(controller);        
    drawable = this.getResources().getDrawable(R.drawable.ic_launcher);
    mapOverlays = mapView.getOverlays();        
    itemizedOverlay = new MyPositionItemizedOverlay(drawable);
    OverlayItem overlayitem = new OverlayItem(point, "", "");       
    itemizedOverlay.addOverlay(overlayitem);
    mapOverlays.add(itemizedOverlay);
 }
  private GeoPoint locate(MapController controller) {
    locationManager = (LocationManager)  getSystemService 

          (Context.LOCATION_SERVICE);
    String provider = LocationManager.GPS_PROVIDER;
    Location location = locationManager.getLastKnownLocation(provider); 
    double lat=0.0;
    double lng = 0.0;
    if (location != null) {
         lat = location.getLatitude();
         lng = location.getLongitude();
    }else{
        lat = 39.92;//北京经纬度
        lng = 116.46;
    }       
    GeoPoint point = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
    controller.animateTo(point);
    return point;
}

@Override
protected boolean isRouteDisplayed() {
    return false;
}
}


 <?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/mainlayout"
     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:clickable="true"
    android:enabled="true"
    android:apiKey="AIzaSyClsUZ05RZ4oXdkMjlR1H4xDM-msmoh1vI"/>


    <LinearLayout
    android:id="@+id/zoomview"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@id/mapview"
    android:layout_centerHorizontal="true"
    />

    </RelativeLayout>
    <!-- uses-permission -->
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission                 

       android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
 <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />

         <meta-data
       android:name="com.google.android.gms.version"
          android:value="AIzaSyClsUZ05RZ4oXdkMjlR1H4xDM-msmoh1vI"/>

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

logcat 显示:

[MapActivity.java:376:handleMessage()] 无法获取连接工厂客户端

求救,请问~有什么问题吗?

4

1 回答 1

1

检查使用的密钥是否有效 API 密钥

并检查您的 API 控制台 Google Maps API 服务是否应该开启

Google API 控制台 - 服务 - Google Maps API v2 for version 2 将其切换为 ON

于 2013-11-12T09:09:16.863 回答