ngày 24-03-2016
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="API_KEY"/> |
Với API_KEY là được lấy từ Google Developers
<meta-data
android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> |
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <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"/> |
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="tranduythanh.com.learngooglemap" android:versionCode="1" android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <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" />
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19" />
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyAWPt-7pVRw-HUBoy9J8_YtB6qPDpp94lM" />
<activity android:name=".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> |
GoogleMap map = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE); map.getUiSettings().setZoomControlsEnabled(true); map.setMyLocationEnabled(true); |
MapFragment mapFragment = MapFragment.newInstance();
GoogleMap mMap = mapFragment.getMap(); mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); getFragmentManager().beginTransaction().add(R.id.container,mapFragment).commit();</pre> |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="tranduythanh.com.learngooglemap.MainActivity" > <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.MapFragment" /> </LinearLayout> |
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.SupportMapFragment" > </fragment> |
MapFragment.newInstance(GoogleMapOptions)
MapView(Context, GoogleMapOptions) |
LatLng TTTH_KHTN = new LatLng(10.763181, 106.675664); MarkerOptions option=new MarkerOptions(); option.position(TTTH_KHTN); option.title("Trung tâm tin học ĐH KHTN").snippet("This is cool"); option.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)); option.alpha(0.8f); option.rotation(90); Marker maker = map.addMarker(option); maker.showInfoWindow(); map.moveCamera(CameraUpdateFactory.newLatLngZoom(TTTH_KHTN, 15)); |
map.setOnMapLoadedCallback(new OnMapLoadedCallback() {
@Override public void onMapLoaded() { // TODO Auto-generated method stub //Xử lý ở đây nầy Log.i("MAP LOADED", "END"); } }); |
Nguồn: Thầy Trần Duy Thanh - Giảng viên tại Trung Tâm Tin Học ĐH Khoa Học Tự Nhiên