java Android Google Maps V2 - XML中的MapView

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java Android Google Maps V2 - XML中的MapView相关的知识,希望对你有一定的参考价值。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    
    <com.google.android.gms.maps.MapView android:id="@+id/mapview"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" />

</LinearLayout>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
	package="com.example"
	android:versionCode="1"
	android:versionName="1.0" >
	
	<uses-sdk
		android:minSdkVersion="8"
		android:targetSdkVersion="15" />
	
	<uses-permission android:name="android.permission.INTERNET"/>
	<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
	<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
	<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
	
	<uses-feature
		android:glEsVersion="0x00020000"
		android:required="true"/>
	
	<permission
		android:name="com.example.permission.MAPS_RECEIVE"
		android:protectionLevel="signature"/>
	<uses-permission android:name="com.example.permission.MAPS_RECEIVE"/>
	
	<application
		android:icon="@drawable/ic_launcher"
		android:label="@string/app_name"
		android:theme="@style/AppTheme" >
		
		<meta-data
			android:name="com.google.android.maps.v2.API_KEY"
			android:value="your_key"/>
		
		<activity
			android:name=".HomeActivity"
			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>
 
public class SomeFragment extends Fragment {
 
	MapView mapView;
	GoogleMap map;
 
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.some_layout, container, false);
 
 		// Gets the MapView from the XML layout and creates it
		mapView = (MapView) v.findViewById(R.id.mapview);
		mapView.onCreate(savedInstanceState);
 
		// Gets to GoogleMap from the MapView and does initialization stuff
		map = mapView.getMap();
		map.getUiSettings().setMyLocationButtonEnabled(false);
		map.setMyLocationEnabled(true);

		// Needs to call MapsInitializer before doing any CameraUpdateFactory calls
		try {
			MapsInitializer.initialize(this.getActivity());
		} catch (GooglePlayServicesNotAvailableException e) {
			e.printStackTrace();
		}
		
		// Updates the location and zoom of the MapView
		CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10);
		map.animateCamera(cameraUpdate);
 
		return v;
	}

	@Override
	public void onResume() {
		mapView.onResume();
		super.onResume();
	}
 
	@Override
	public void onDestroy() {
		super.onDestroy();
		mapView.onDestroy();
	}
 
	@Override
	public void onLowMemory() {
		super.onLowMemory();
		mapView.onLowMemory();
	}
 
}

以上是关于java Android Google Maps V2 - XML中的MapView的主要内容,如果未能解决你的问题,请参考以下文章

java Android Google Maps V2 - XML中的MapView

谷歌地图 V2 中的错误 java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment

java Android - google maps v2 - 从字符串/ coor加载地址的任务。

java Android - google maps v2 - 从字符串/ coor加载地址的任务。

java Android - google maps v2 - 从字符串/ coor加载地址的任务。

java Android - google maps v2 - 从字符串/ coor加载地址的任务。