资源描述
,单击此处编辑母版标题样式,2011/12/5,#,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,Android GPS,开发,GPS,:,24,颗卫星,,12,小时的周期,进行定位。,GoogleMap,是,Google,公司提供的电子地图。,三,种地图:矢量地图、卫星照片、地形视图。,GoogleMap,的主要功能:地图浏览、搜索地图、搜索周边、行车路线等。,Google Map,与,GPS,概述,MapActivity,MapView,通过上面两个类就可以直接调用,GoogleMap,LocationManager,:提供系统位置的访问方法。,LocationProvider,:提供位置服务的访问方法。,几个重要的术语,通过,LocationManager,可以实现设备的定位、追踪和趋近提示。,通过,Context.getSystemService(Context.LOCATION_SERVICE),方法获得该类的实例,。,LocationManager,周期性地提供设备的地理位置。,Each provider has a set of,criteria,under which it may be used;for example,some providers require GPS hardware and visibility to a number of satellites;others require the use of the cellular radio,or access to a specific carriers network,or to the internet.They may also have different battery consumption characteristics or monetary costs to the user.The,Criteria,class allows providers to be selected based on user-specified criteria.,LocationProvider,根据设备,可以获得不同的定位设备,通过不同的定位技术来获得不同位置服务,也就是不同的,LocationProvider,。,不同的,LocationProvider,决定了定位能力,包括精确度、费用、耗电等,还有一些方向、速度、和高度等信息。,一、可以通过指定名称来获得,LocationProvider,。,locationManager.getProvider(LocationManager.GPS_PROVIDER),获得,LocationProvider,二、获得当前可利用的,LocaitonProvider,locationProvider.getProviders(true);,三、根据,Criteria,条件获得,LocationProvider,Criteria,封装了获得,LocationProvider,的条件,可以根据指定的条件来过滤获得,LocationProvider.,定位就是确定设备的位置。,Location,类描述了设备的地理位置信息:经度、纬度、方向、高度、速度等。,通过,LocationManager,的,getLastKownLocation(LocationProvider),方法可以获得,Location,的实例。,定位,跟踪是通过注册位置监听器实现的。,声明一个,LocationListener,,实现其,onLocationChanged(),方法,在该方法中实现位置变化的代码。当位置发生变化时,监听器被触发,就调用,onLocationChanged().,通过,LocationManager,的,requestLocationUpdates,方法注册监听器。,跟踪,趋近告警就是当设备进入或退出某个设定的区域时进行提示。,LocationManager,提供了一个方法:,addProximityAlert,(,double latitude,double longitude,float radius,long expiration,PendingIntent,intent,),趋近告警,To make it easier for you to add powerful mapping capabilities to your application,Google provides a Maps external library that includes the com.google.android.maps package.The classes of the com.google.android.maps package offer built-in downloading,rendering,and caching of Maps tiles,as well as a variety of display options and controls.,Google Maps External Library,The key class in the Maps package is,com.google.android.maps.MapView,a subclass of ViewGroup.A MapView displays a map with data obtained from the,Google Maps service,.When the MapView has focus,it will capture keypresses and touch gestures to pan and zoom the map automatically,including handling network requests for additional maps tiles.It also provides all of the UI elements necessary for users to control the map.Your application can also use MapView class methods to control the MapView programmatically and draw a number of Overlay types on top of the map.,In general,the MapView class provides a wrapper around the Google Maps API that lets your application manipulate Google Maps data through class methods,and it lets you work with Maps data as you would,other,types of Views,.,The Maps external library is not part of the standard Android library,so it may not be present on some compliant Android-powered devices.Similarly,the Maps external library is not included in the standard Android library provided in the SDK.So that you can develop using the classes of the com.google.android.maps package,the Maps external library is made available to you as part of the Google APIs add-on for the Android SDK.,Registering for a Maps API Key is simple,free,and has two parts:,Registering the MD5 fingerprint of the certificate that you will use to sign your application.The Maps registration service then provides you a Maps API Key that is associated with your applications signer certificate.,Adding a reference to the Maps API Key in each MapView,whether declared in XML or instantiated directly from code.You can use the same Maps API Key for any MapView in any Android application,provided that the application is signed with the certificate whose fingerprint you registered with the service.,Obtaining a Maps API Key,If you are using Eclipse/ADT and are unsure where the debug keystore is located,you can select,Windows Prefs Android Build,to check the full path,which you can then paste into a file explorer to locate the directory containing the,keystore,.,Next,run Keytool with the-list option,against the target,keystore,and key alias.,keytool-list-alias alias_name-keystore my-release-key.keystore,Getting the MD5 Fingerprint of the SDK Debug Certificate,Final Steps to Enable MapView Elements,If youve added the Maps API Key to the MapViews in your application,here are the final steps to enable the MapView elements to run properly:,Make sure that you added a,element referencing the external com.google.android.maps library.The element must be a child of the element in the applications manifest.,
展开阅读全文