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()] 接続ファクトリ クライアントを取得できませんでした
SOSお願いします~何が問題なの?