資源描述:
《Android地圖和定位學(xué)習(xí)總結(jié)》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、Android地圖和定位學(xué)習(xí)總結(jié)首屆Google暑期大學(xué)生博客分享大賽——2010Android篇android.location包下有這么一些接口和類:InterfacesGpsStatus.ListenerGpsStatus.NmeaListenerLocationListenerClassesAddressCriteriaGeocoderGpsSatelliteGpsStatusLocationLocationManagerLocationProvidercom.google.android.map
2、s包下有這些類:AllClassesGeoPointItemizedOverlayItemizedOverlay.OnFocusChangeListenerMapActivityMapControllerMapViewMapView.LayoutParamsMapView.ReticleDrawModeMyLocationOverlayOverlayOverlay.SnappableOverlayItemProjectionTrackballGestureDetector我們邊看代碼邊熟悉這些類。要獲取當(dāng)
3、前位置坐標(biāo),就是從Location對象中獲取latitude和longitude屬性。那Location對象是如何創(chuàng)建的?LocationManagerlocMan=(LocationManager)getSystemService(Context.LOCATION_SERVICE);//LocationManager對象只能這么創(chuàng)建,不能用newLocationlocation=locMan.getLastKnownLocation(LocationManager.GPS_PROVIDER);if(lo
4、cation==null){location=locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);}//注意要為應(yīng)用程序添加使用權(quán)限所謂getLastKnownLocation自然是獲取最新的地理位置信息,那LocationManager.GPS_PROVIDER和LocationManage
5、r.NETWORK_PROVIDER有什么區(qū)別呢?俺也不是學(xué)通信的,對這個不了解,在網(wǎng)上看到有人想“在室外有GPS定位,在室內(nèi)想用Wifi或基站定位”。除了直接使用LocationManager提供的靜態(tài)Provider(如GPS_PROVIDER和NETWORK_PROVIDER等)外,還可以使用我們自己創(chuàng)建的LocationProvider對象。創(chuàng)建LocationProvider對象一般要先創(chuàng)建Criteria對象,來設(shè)置我們的LocationProvider要滿足什么樣的標(biāo)準(zhǔn)CriteriamyC
6、ri=newCriteria();myCri.setAccuracy(Criteria.ACCURACY_FINE);//精確度myCri.setAltitudeRequired(false);//海拔不需要myCri.setBearingRequired(false);//Bearing是“軸承”的意思,此處可理解為地軸線之類的東西,總之BearingInformation是一種地理位置信息的描述myCri.setCostAllowed(true);//允許產(chǎn)生現(xiàn)金消費myCri.setPowerReq
7、uirement(Criteria.POWER_LOW);//耗電StringmyProvider=locMan.getBestProvider(myCri,true);publicStringgetBestProvider(Criteriacriteria,booleanenabledOnly)Returnsthenameoftheproviderthatbestmeetsthegivencriteria.Onlyprovidersthatarepermittedtobeaccessedbythecal
8、lingactivitywillbereturned.Ifseveralprovidersmeetthecriteria,theonewiththebestaccuracyisreturned.Ifnoprovidermeetsthecriteria,thecriteriaareloosenedinthefollowingsequence:powerrequirementaccuracybearingspeedaltitude