我有一个扩展MapActivity的活动。运行该活动后,Google Map应该显示在模拟器上。 我该怎么做?Android:如何打开Google Map?
回答
http://www.vogella.de/articles/AndroidLocationAPI/article.html#overview_maps
这个环节得到了什么ü需要。
我做到了。它也适用于我。
只需转到索引中的第4个主题即可。 (谷歌地图)
感谢
更新:
Menifest文件:
<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; import 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) {
}
}
}
请不要忘记标记此答案asCorrect :)希望我帮助你... – Shah 2011-05-17 11:07:22
我得到了这个异常'03- 28 10:03:05.978:E/AndroidRuntime(354):致命例外:main 03-28 10:03:05.978:E/AndroidRuntime(354):java.lang.RuntimeException:无法实例化活动ComponentInfo {com.williamroma .example/com.williamroma.example.GoogleMapActivity}:java.lang.ClassNotFoundException:com.williamroma.example.GoogleMapActivity in loader dalvik.system.PathClassLoader [/data/app/com.williamroma.example-1.apk] ' – 2013-03-28 10:09:04
启动的MapView然后按照这个mapview's link
你必须立即登记here,然后插入您的布局像这样提供的代码:
<com.google.android.maps.MapView
android:id="@+id/map_map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="***************************************"
/>
你可以参考这个链接,http://developer.android.com/resources/tutorials/views/hello-mapview.html
检查一下您是否正确提供您的地图API密钥。这个链接帮助我用我现在的位置显示地图。
MapActivity显示Google Map。更加详细一些。 – 2011-05-17 09:25:11
“如果你问一个模糊的问题,你会得到一个模糊的答案,但如果你给我们提供了细节和上下文,我们可以提供一个有用的答案。” - [如何提问常见问题](http://stackoverflow.com/questions/how-to-ask) – slhck 2011-05-17 09:27:17