Android:如何打开Goog​​le地图?

时间:2011-05-17 09:23:41

标签: android google-maps

我有一个扩展MapActivity的活动。运行活动后,Google Map应显示在模拟器上。 我怎么能这样做?

4 个答案:

答案 0 :(得分:3)

http://www.vogella.de/articles/AndroidLocationAPI/article.html#overview_maps
这个链接得到了你需要的东西 我做的。它也适用于我..
转到索引的第4个主题。 (谷歌地图)

由于

<强>更新:
清单文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.vogella.android.locationapi.maps" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".ShowMap" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <uses-library android:required="true" android:name="com.google.android.maps"></uses-library>

</application>

XML LayoutFile:

<?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:apiKey="Your Maps API Key"
/>

</RelativeLayout>  

活动:

导入com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController; 导入com.google.android.maps.MapView;

公共类ShowMap扩展了MapActivity {

private MapController mapController;
private MapView mapView;
private LocationManager locationManager;

public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.main); // bind the layout to the activity

    // create a map view
    RelativeLayout linearLayout = (RelativeLayout) findViewById(R.id.mainlayout);
    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);
    mapView.setStreetView(true);
    mapController = mapView.getController();
    mapController.setZoom(14); // Zoon 1 is world view
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
            0, new GeoUpdateHandler());
}

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

public class GeoUpdateHandler implements LocationListener {

    @Override
    public void onLocationChanged(Location location) {
        int lat = (int) (location.getLatitude() * 1E6);
        int lng = (int) (location.getLongitude() * 1E6);
        GeoPoint point = new GeoPoint(lat, lng);
        mapController.animateTo(point); //  mapController.setCenter(point);
    }

    @Override
    public void onProviderDisabled(String provider) {
    }

    @Override
    public void onProviderEnabled(String provider) {
    }

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

答案 1 :(得分:2)

启动mapview,然后按照mapview's link

进行操作

答案 2 :(得分:1)

您必须注册here,然后插入布局中提供的代码,如下所示:

<com.google.android.maps.MapView
    android:id="@+id/map_map"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:apiKey="***************************************"
/>

答案 3 :(得分:1)

您可以参考此链接http://developer.android.com/resources/tutorials/views/hello-mapview.html

检查您是否正确提供了Map API密钥。此链接帮助我显示了当前位置的地图。