Friday, January 8, 2010

Bắt đầu với google maps trên android

Trước tiên bạn phải đăng ký một cái maps API key của google bằng cách vào
http://code.google.com/android/maps-api-signup.html
Trước đó bạn phải kiếm cái MD5 của máy mình đã bằng cách
Kiểm tra thư mục C:Documents and Settings<UserName>.android
Của mình cụ thể là C:Documents and SettingsTanNM.android
Bạn sẽ thấy cái file debug.keystore
copy nó vào trong C:Program FilesJavajdkbin
trên dòng lệnh command bạn cd vào thư mục C:Program FilesJavajdkbin
Chạy câu lệnh:
keytool -list -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android

Sẽ được một kq giống như:
   1. androiddebugkey, Oct 27, 2009, PrivateKeyEntry,
   2. Certificate fingerprint (MD5): E1:D0:F8:0C:F7:11:F0:04:F9:F7:2F:21:49:DD:F7:B3

Sau đó vào trang
http://code.google.com/android/maps-api-signup.html
điền cái mã MD5:
E1:D0:F8:0C:F7:11:F0:04:F9:F7:2F:21:49:DD:F7:B3

vào và submit, ta sẽ có một key giống như:
09BcO4uoQ0MIS9P9FU2G2MK2imfqIE5kvrJ8JRA

Ngon roài!!!!!!

Tiếp đến ta tạo một ứng dụng đơn giản trên myeclipse
file Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="com.ftl.map">
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
        <uses-permission android:name="android.permission.INTERNET" />
        <application android:label="@string/activity_sample_code"
               android:icon="@drawable/icon">
                <uses-library android:name="com.google.android.maps" />
                <activity android:name="com.ftl.map.view.MapViewDemo"
                       android:label="MapView">
                        <intent-filter>
                                <action android:name="android.intent.action.MAIN" />
                                <category android:name="android.intent.category.SAMPLE_CODE" />
                        </intent-filter>
                </activity>
        </application>
</manifest>

file main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/main" android:layout_width="fill_parent"
       android:layout_height="fill_parent">
        <com.google.android.maps.MapView
               android:layout_width="fill_parent" android:layout_height="fill_parent"
               android:enabled="true" android:clickable="true" android:apiKey="09BcO4uoQ0MIS9P9FU2G2MK2imfqIE5kvrJ8JRA" />
</LinearLayout>


file java Activity

package com.ftl.map.view;

import android.os.Bundle;

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

public class MapViewDemo extends MapActivity {

        private MapView myMapView;

        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(com.ftl.map.R.layout.main);
        }

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

Chạy nào!!!!!

No comments:

Post a Comment