Вы находитесь на странице: 1из 33

ThongDM www.vietandroid.

com

Tng quan v Google Maps API Truy vn trong Google Maps Mt s kinh nghim ng dng ViAMap ( VietAndroid Map )

L mt b th vin m rng ca Android SDK

Tt c nm trong com.google.android.maps Lp chnh l

com.google.android.maps.MapView

H tr ht cc thao tc ngi dng ( Zoom in, Zoom out, click event) H tr hin th cc Overlay ty bin

Ti v ci t Google APIs Add-on ng k API Key http://code.google.com/android/addons/google-apis

Tm kim a im Dn ng Tnh khong cch www.maps.google.com

Bi ton : Tm 20 cy ATM gn v tr hin ti ca bn. Bc 1: Tm tt c cc cy ATM http://maps.google.com/maps?q=atm q y l Querry ( Truy vn )

Bc 2: Gii hn li kt qu bng cch truyn vo ta v tr hin ti ca bn V d : V tr hin ti l Nh th ln H Ni (21.029505,105.850566) http://maps.google.com/maps?q=atm&sll=2 1.029505,105.850566 Kt qu chnh xc hn rt nhiu. Tham s sll ( Search latitude, longitude )

Bc 3 : Ly 20 kt qu tr v http://maps.google.com/maps?q=atm&sll=2 1.029505,105.850566&num=20 Tham s num ( number )

S dng kt qu truy vn trn trang www.maps.google.com vo ng dng ca bn. S dng tham s output ( XML, HTML, JS ) http://maps.google.com/maps?q=atm&sll=2 1.029505,105.850566&num=20&output=kml

Truy vn vi Google Maps

Default Handler

Truy vn vi Google Maps


Tham kho thm cc thng s http://mapki.com/wiki/Google_Map_Paramet ers

V trn MapView Cc xc nh v tr hin ti hiu qu nht

Overlay Item vi Transparent Info Window

Transparent Panel

Paint myPaint = new Paint(); myPaint.setARGB(175, 75, 75, 75); ARGB = Alpha ( Transparent ) , Red, Green , Blue public class MyOverlay extends Overlay { @Override public void draw(Canvas canvas, MapView mapView, boolean shadow) { RectF infoWindowRect = new RectF(0,0,125,25); canvas.drawRoundRect(infoWindowRect, 5, 5, myPaint } }

public class TransparentPanel extends LinearLayout { @Override protected void dispatchDraw(Canvas canvas) { RectF drawRect = new RectF(); drawRect.set(0 ,0, 50 , 300); canvas.drawRoundRect(drawRect, 5, 5, myPaint); super.dispatchDraw(canvas); }

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:id="@+id/balloon_inner_layout"> <TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:textColor="#FF000000"></TextView> <TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="12dip"></TextView> </LinearLayout> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="8dip"></ImageView> </LinearLayout>

@Override protected final boolean onTap(int index) { balloonView = (View) balloonView.findViewById (R.layout.balloon_overlay); balloonView.setVisibility(View.VISIBLE); return true; }

Cch xc nh v tr hin ti hiu qu nht Tm kim hiu qu vi Google Maps

GPS Network Provider


u im : Rt chnh xc Nhc im : Mt nhiu thi gian nh v
u im : Nhanh Nhc im : V tr khng chnh xc nh GPS

Using last location result

Using Network Provider

Using GPS

private void registerLocationListeners() { locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); Criteria fine = new Criteria(); fine.setAccuracy(Criteria.ACCURACY_FINE); Criteria coarse = new Criteria(); coarse.setAccuracy(Criteria.ACCURACY_COARSE); currentLocation = locationManager.getLastKnownLocation( locationManager.getBestProvider(fine, true)); if (listenerFine == null || listenerCoarse == null) createLocationListeners(); locationManager.requestLocationUpdates( locationManager.getBestProvider(coarse, true), 5000, 1000, listenerCoarse); locationManager.requestLocationUpdates( locationManager.getBestProvider(fine, true), 5000, 50, listenerFine); }

Tm a im, ng i .... Dn ng v tnh khong cch Tm kim nhanh vi cc a im thng dng Giao din p, d s dng Phin bn 1.0 c trn ViMarket

THE END THANKS FOR LISTENING

Вам также может понравиться