0

这是我的清单文件:

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <uses-library android:name="com.google.android.maps"/>
    <activity
        android:name="com.docuart.maps.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

这是我的布局:

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

   <com.google.android.maps.MapView
  android:id="@+id/mapGoogle"
  android:enabled="true"
  android:clickable="true"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"                 
             android:apiKey="my api key" />

</LinearLayout>

这是我的代码:

public class MainActivity extends MapActivity {


private static final int MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1;//metre 
private static final int MINIMUM_TIME_BETWEEN_UPDATES = 1000;//milisaniye

protected LocationManager locationManager;
MapView mView;
MapController mapController;
GeoPoint gPoint;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mView = (MapView) findViewById(R.id.mapGoogle);

    mView.displayZoomControls(true);
    mView.setBuiltInZoomControls(true);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,   MINIMUM_TIME_BETWEEN_UPDATES , MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, new MyLocationListener());


    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    if(location != null){
        gPoint = new GeoPoint((int)(location.getLatitude()*1000000),(int)(location.getLongitude()*1000000));

        mapController = mView.getController();
        mapController.animateTo(gPoint);            
        mapController.setZoom(14);
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

public class MyLocationListener implements LocationListener{
    @Override
    public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub
 gPoint = new GeoPoint((int)(location.getLatitude()*1000000),(int)(location.getLongitude()*1000000));

        mapController = mView.getController();
        mapController.animateTo(gPoint);

        mapController.setZoom(14);
    }

    @Override
    public void onProviderDisabled(String provider) {
    }

    @Override
    public void onProviderEnabled(String provider) {
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }}

   protected boolean isRouteDisplayed() {
            return false;
        }    
}

项目正在运行,但我看不到我的位置。我找不到哪里可能有问题。要查看屏幕截图:http ://sdrv.ms/Wyf1Z1感谢您的帮助。

4

1 回答 1

0

在您的布局中添加您的实际 2.0 auth api 密钥 android:apiKey="my api key" />,您必须从api 密钥控制台获取。

于 2013-03-18T09:21:08.633 回答