欢迎来到天天文库
浏览记录
ID:44208147
大小:44.50 KB
页数:3页
时间:2019-10-19
《Android通过高德地图进行定位》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、packagecom.example.dingwei;importjava.text.SimpleDateFormat;importjava.util.Date;importcom.amap.api.location.AMapLocation;importcom.amap.api.location.AMapLocationClient;importcom.amap.api.location.AMapLocationClientOption;importcom.amap.api.location.AMapLoc
2、ationClientOption.AMapLocationMode;importcom.amap.api.location.AMapLocationListener;importandroid.app.Activity;importsndroid.content.Context;importandroidJocation.Criteria;importandroidJocation.Location;importandroidJocation.LocationListener;importandroid.l
3、ocation丄ocationManager;importandroid.os.Bundie;importandroid.util.Log;importandroid.view.Menu;importandroid.view.Menultem;importandroid.widget.TextView;publicclassMainActivityextendsActivity{〃声明AMapLocationClient类对象publicAMapLocationClientmLocationClient=nu
4、ll;〃声明定位回调监听器publicAMapLocationListenermLocationListener=newMyListener();〃声明mLocationOption对象publicAMapLocationClientOptionmLocationOption二null;privateLocationManagerlocationManager;privateTextViewlocationText;(©OverrideprotectedvoidonCreate(BundlesavedInst
5、anceState){super,onCreate(savedlnstanceState);setContentView(R.layout.activity_main);locationText=(TextView)findViewByld(R.id.location);set();/*locationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);Criteriacriteria=newCriteria));〃设置规则c
6、riteria.setAccuracy(Criteria.ACCURACY_FINE);〃设置电屋criteria.setPowerRequirement(Criteria.POWER_LOW);Stringprovider=locationManager.getBestProvider(criteria,true);//Stringprovider=locationManager.getAIIProviders().get(l);locationManager.requestLocationUpdates(
7、providec3000,100,newMyListener());*/}publicvoidset(){〃初始化定位mLocationClient=newAMapLocationClient(getApplicationContext());〃设置定位回调监听mLocationClient.setLocationListener(mLocationListener);〃初始化定位参数mLocationOption二newAMapLocationClientOption();〃设置定位模式为高精度模式,Bat
8、tery_Saving为低功耗模式,Device_Sensors是仅设备模式mLocationOption.setLocationMode(AMapLocationMode.Hight_Accuracy);〃设置是否返回地址信息(默认返回地址信息)mLocationOption.setNeedAddress(true);〃设置是否只定位一次,默认为falsemLocationOption.setOn
此文档下载收益归作者所有