You are on page 1of 8

Bt u vi Map-APIs trong Android

http://forum.laptrinhdidong.vn/showthread.php?t=96

Help

Register

Forum

What's New?
Forum Actions Quick Links Advanced Search

Today's Posts FAQ Calendar Community

Forum

Lp Trnh Di ng

Lp trnh Android

Bt u vi Map-APIs trong Android

Results 1 to 4 of 4

Thread: Bt u vi Map-APIs trong Android


View First Unread Thread Tools Display

10-24-2011, 10:16 AM

#1

nhdac
Moderator

Bt u vi Map-APIs trong Android


Mun lp trnh v bn cng nh v tr trong Android, trc tin cc bn phi ng k Map key trong Android, trong phn ny mnh s trnh by cch ly Map key ca mnh v 1 ng dng nho nh s dng bn .

Join Date: Sep 2011 Posts: 97 Thanks: 0 Thanked 22 Times in 13 Posts

u tin cc bn phi xc nh 2 v tr trn a ca 2 tp tin sau: Keytool ca Java: N nm trong folder Java/bin (ni cc bn ci t Java vo my), nu cc bn ci t Java theo kiu mc nh th n nm th mc sau: C:\Program Files\Java\jdk1.7.0\bin. Debug.keystore ca Android: Theo mc nh trong my mnh th n nm : C:\Users\WIN7\.android (l ni cha cc my Virtual Device). Tip theo cc bn vo Command Line. Khi mi vo th thng thng cc bn s thy mc nh nh sau:

1 of 8

2/27/2012 11:01 PM

Bt u vi Map-APIs trong Android

http://forum.laptrinhdidong.vn/showthread.php?t=96

Cc bn a v th mc cha keytool bng cc g: cd C:\Program Files\Java\jdk1.7.0\bin

Sau cc bn g dng lnh sau : keytool.exe -v -list -alias androiddebugkey -keystore "C:\Users \WIN7\.android\debug.keystore" -storepass android -keypass android

2 of 8

2/27/2012 11:01 PM

Bt u vi Map-APIs trong Android

http://forum.laptrinhdidong.vn/showthread.php?t=96

Vy khi g xong cu lnh trn th bn s nhn c m s MD5 ng k Map key (M s dng nh : 94:1E:43:49:87:73:BB:E6:A6:88 7:20:F1:8E:B5:98 ). Tip theo cc bn vo trang web http://code.google.com /android/maps-api-signup.html v nhp ci MD5 ca bn vo :

Tip theo cc bn s nhn c kt qu dng nh: Key Android: zxcvbnmsadfghjlkqwpoeirty MD5: 94:1E:43:49:87:73:BB:E6:A6:88 7:20:F1:8E:B5:98 test: <com.google.android.maps.MapView android:layout_width="fill_parent" android:layout_height="fill_parent" android:apiKey=" zxcvbnmsadfghjlkqwpoeirty" />

3 of 8

2/27/2012 11:01 PM

Bt u vi Map-APIs trong Android

http://forum.laptrinhdidong.vn/showthread.php?t=96

Cc bn lu kt qu ny li vo 1 trang notepad hay word g v k t y v sau mi khi cn dng ng dng map th bn ch cn copy c ci on test trn vo phn layout l xong (c th thm vi thuc tnh nu bn thch). V tip theo mnh s to 1 ng dng minh ha v MapView: Project : Project name: TestMap2 Build Target: Google APIs platform 2.2 Application name: TestMap2 Package name: com.dac Create Activity: TestMap2Activity Cc bn lu l khi mun s dng cc th vin ca google v Map th cc bn phi to target ca Project l Google APIs v to target ca Virtual Devices tng ng. Cc bn thm uses-permission v uses-library vo file AndroidManifest.xml nh sau: PHP Code:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.andro id.com/apk/res/android" package="com.dac" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <usespermission android:name="android.permission.I NTERNET"/> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <useslibrary android:name="com.google.android.maps "/> <activity android:label="@string/app_name" android:name=".TestMap2Activity" > <intent-filter > <action android:name="android .intent.action.MAIN" /> <category android:name="andro id.intent.category.LAUNCHER" />

Trong file main.xml: PHP Code:


<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.a ndroid.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content"

4 of 8

2/27/2012 11:01 PM

Bt u vi Map-APIs trong Android

http://forum.laptrinhdidong.vn/showthread.php?t=96

android:text="Nobilomo@gmail.com" /> <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/btnZoomOut" android:layout_width="wrap_conten t" android:layout_height="wrap_conte nt" android:text="-" /> <Button android:id="@+id/btnSat" android:layout_width="wrap_conten t" android:layout_height="wrap_conte nt"

V file TestMap2Activity.java c code x l nh sau: PHP Code:


package com.dac; import import import import import android.app.Activity; android.os.Bundle; android.view.View; android.view.View.OnClickListener; android.widget.Button;

import com.google.android.maps.*; public class TestMap2Activity extends MapActi vity { OnClickListener o = new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stu b MapView mv = (MapView)findViewByI d(R.id.MapView); switch (v.getId()) { case R.id.btnZoomIn: mv.getController().zoomIn(); break; case R.id.btnZoomOut: mv.getController().zoomOut(); break; case R.id.btnSat: mv.setSatellite(true);

Khi debug ng dng cc bn s c kt qu nh sau:

5 of 8

2/27/2012 11:01 PM

Bt u vi Map-APIs trong Android

http://forum.laptrinhdidong.vn/showthread.php?t=96

Reply With Quote

Today, 11:08 AM

#2

handsome89
Junior Member

anh oi giup em voi em bi loi nay khong biet sua the nao bay h error.jpg tks anh nhieu.

Join Date: Feb 2012 Posts: 2 Thanks: 0 Thanked 0 Times in 0 Posts

Reply With Quote

Today, 11:11 AM

#3

handsome89
Junior Member

Join Date: Feb 2012 Posts: 2 Thanks: 0 Thanked 0 Times in 0 Posts

6 of 8

2/27/2012 11:01 PM

Bt u vi Map-APIs trong Android

http://forum.laptrinhdidong.vn/showthread.php?t=96

em khong sao up dc cai nh n to hn c na..sory cc anh trn din n by h em b li ny THE APPLICATION MAPVIEW(PROCESS COM.DAC) HAS STOPPED UNEXPECTEDLY. PLEASE TRY AGAIN mong cac anh ch dy em iu ny.

Hnh c nh km error.jpg (21.3 KB, 0 xem)

Last edited by handsome89; Today at 11:17 AM. Reply With Quote

Today, 04:38 PM

#4

van.le
Junior Member

hi bn! sau khi ng k key map th ta s b on code nhn v u vy bn? trong layout/main.xml afh ?

Join Date: Feb 2012 Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts

Reply With Quote

Quick Navigation

Lp trnh Android

Top

Previous Thread | Next Thread

7 of 8

2/27/2012 11:01 PM

Bt u vi Map-APIs trong Android

http://forum.laptrinhdidong.vn/showthread.php?t=96

All times are GMT +7. The time now is 10:58 PM. Powered by vBulletin Version 4.1.7 Copyright 2012 vBulletin Solutions, Inc. All rights reserved.

8 of 8

2/27/2012 11:01 PM

You might also like