Android地图和定位学习总结Word版

上传人:人*** 文档编号:487402695 上传时间:2023-12-21 格式:DOC 页数:13 大小:68KB
返回 下载 相关 举报
Android地图和定位学习总结Word版_第1页
第1页 / 共13页
Android地图和定位学习总结Word版_第2页
第2页 / 共13页
Android地图和定位学习总结Word版_第3页
第3页 / 共13页
Android地图和定位学习总结Word版_第4页
第4页 / 共13页
Android地图和定位学习总结Word版_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《Android地图和定位学习总结Word版》由会员分享,可在线阅读,更多相关《Android地图和定位学习总结Word版(13页珍藏版)》请在金锄头文库上搜索。

1、Android地图和定位学习总结首届 Google 暑期大学生博客分享大赛2010 Android 篇android.location包下有这么一些接口和类:InterfacesGpsStatus.ListenerGpsStatus.NmeaListenerLocationListenerClassesAddressCriteriaGeocoderGpsSatelliteGpsStatusLocationLocationManagerLocationProvidercom.google.android.maps包下有这些类:All ClassesGeoPointItemizedOverlayI

2、temizedOverlay.OnFocusChangeListenerMapActivityMapControllerMapViewMapView.LayoutParamsMapView.ReticleDrawModeMyLocationOverlayOverlayOverlay.SnappableOverlayItemProjectionTrackballGestureDetector我们边看代码边熟悉这些类。 要获取当前位置坐标,就是从Location对象中获取latitude和longitude属性。那Location对象是如何创建的?LocationManager locMan=(L

3、ocationManager)getSystemService(Context.LOCATION_SERVICE);/LocationManager对象只能这么创建,不能用newLocationlocation=locMan.getLastKnownLocation(LocationManager.GPS_PROVIDER);if(location=null) location=locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);/注意要为应用程序添加使用权限推荐精选 所谓getLastKnownLocation自然是获取

4、最新的地理位置信息,那LocationManager.GPS_PROVIDER和LocationManager.NETWORK_PROVIDER有什么区别呢?俺也不是学通信的,对这个不了解,在网上看到有人想“在室外有GPS定位,在室内想用Wifi或基站定位”。除了直接使用LocationManager提供的静态Provider(如GPS_PROVIDER和NETWORK_PROVIDER等)外,还可以使用我们自己创建的LocationProvider对象。创建LocationProvider对象一般要先创建Criteria对象,来设置我们的LocationProvider要满足什么样的标准Cr

5、iteria myCri=new Criteria();myCri.setAccuracy(Criteria.ACCURACY_FINE);/精确度myCri.setAltitudeRequired(false);/海拔不需要myCri.setBearingRequired(false);/Bearing是“轴承”的意思,此处可理解为地轴线之类的东西,总之Bearing Information是一种地理位置信息的描述myCri.setCostAllowed(true);/允许产生现金消费myCri.setPowerRequirement(Criteria.POWER_LOW);/耗电Strin

6、g myProvider=locMan.getBestProvider(myCri,true);public String getBestProvider (Criteria criteria, boolean enabledOnly)Returns the name of the provider that best meets the given criteria. Only providers that are permitted to be accessed by the calling activity will be returned. If several providers m

7、eet the criteria, the one with the best accuracy is returned. If no provider meets the criteria, the criteria are loosened in the following sequence:power requirementaccuracybearingspeedaltitudeNote that the requirement on monetary cost is not removed in this process.Parameterscriteria the criteria

8、that need to be matchedenabledOnly if true then only a provider that is currently enabled is returnedReturnsname of the provider that best matches the requirementsonly翻译为“最适合的Location location=locMan.getLastKnownLoation(myProvider);double latitude=location.getLatitude();/获取纬度double longitude=locatio

9、n.getLongitude();/获取经度我想知道当前位置描述(比如“武汉华中科技大学”而不是一个经纬值)呢?这就要使用GeoCoder创建一个Address对象了。Geocoder gc=new Geocoder(context,Locale.CHINA);/Locale是java.util中的一个类List listAddress=gc.getFromLocation(latitude,longitude,1);推荐精选List getFromLocation(double latitude, double longitude, int maxResults)Returns an arr

10、ay of Addresses that are known to describe the area immediately surrounding the given latitude and longitude.(返回给定经纬值附近的一个Address)既然是“附近”那实际编码时我们没必要把经纬值给的那么精确,而取一个近似的整数,像这样:/*自经纬度取得地址,可能有多行地址*/List listAddress=gc.getFromLocation(int)latitude,(int)longitude,1);StringBuilder sb=new StringBuilder();/*判

11、断是不否为多行*/if(listAddress.size()0) Address address=listAddress.get(0);for(int i=0;iaddress.getMaxAddressLineIndex();i+)sb.append(address.getAddressLine(i).append(n);sb.append(address.getLocality().append(n);sb.append(address.getPostalCode().append(n);sb.append(address.getCountryName ().append(n);publi

12、c int getMaxAddressLineIndex ()Since: API Level 1Returns the largest index currently in use to specify an address line. If no address lines are specified, -1 is returned.public String getAddressLine (int index)Since: API Level 1Returns a line of the address numbered by the given index (starting at 0

13、), or null if no such line is present.String getCountryName()Returns the localized country name of the address, for example Iceland, or null if it is unknown.String getLocality()Returns the locality of the address, for example Mountain View, or null if it is unknown. 反过来我们可以输入地址信息获取经纬值Geocoder mygeo

14、Coder=new Geocoder(myClass.this,Locale.getDefault();List lstAddress=mygeoCoder.getFromLocationName(strAddress,1);/strAddress是输入的地址信息推荐精选if(!lstAddress.isEmpty()Address address=lstAddress.get(0);double latitude=address.getLatitude()*1E6;double longitude=adress.getLongitude()*1E6;GeoPoint geopoint=new

15、 GeoPoint(int)latitude,(int)longitude); A class for handling geocoding and reverse geocoding. Geocoding is the process of transforming a street address or other description of a location into a (latitude, longitude) coordinate. Public ConstructorsGeocoder(Context context, Locale locale)Constructs a Geocoder whose responses will be localized for the

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 资格认证/考试 > 自考

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号