日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android 获取经纬度,地理位置,省市区

發布時間:2023/12/10 Android 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android 获取经纬度,地理位置,省市区 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

申請百度key:http://lbsyun.baidu.com/

?

?

1、jar包下載地址:https://pan.baidu.com/s/1J-boj0ct9oJ8YjXMR8X4KA

下載并復制到libs下,Add As Library

?

如需獲取SHA1值:https://blog.csdn.net/meixi_android/article/details/72547966

2、jar包復制到libs文件下,并Add As library

3、Java代碼

?

static BDLocation lastLocation = null; private LocationClient mLocClient; public MyLocationListenner myListener = new MyLocationListenner();//自定義方法 public class MyLocationListenner implements BDLocationListener {@Overridepublic void onReceiveLocation(BDLocation location) {if (location == null) {return;}if (lastLocation != null) {if (lastLocation.getLatitude() == location.getLatitude() && lastLocation.getLongitude() == location.getLongitude()) {Log.d("map", "same location, skip refresh");// mMapView.refresh(); //need this refresh?return;}}String addrlg; //定位結果lastLocation = location;if (!TextUtils.isEmpty(lastLocation.getLocationDescribe())){addrlg = lastLocation.getLocationDescribe();}else if (lastLocation.hasAddr()) {addrlg = lastLocation.getAddrStr();}else {addrlg = "定位失敗...";return;} // String city = lastLocation.getCity();double lat = lastLocation.getLatitude();double lot = lastLocation.getLongitude();ShareUtil.sharedPstring("nowla",String.valueOf(lat));ShareUtil.sharedPstring("nowlo",String.valueOf(lot));ShareUtil.sharedPstring("nowad",addrlg);Log.i("lgq","............"+addrlg+"........"+lat+"......."+lot); // Toast.makeText(MainActivity.this, addrlg+"........"+lat, Toast.LENGTH_SHORT).show(); // tv_bottom_bar_me.setText(addrlg); // mBaiduMap.animateMapStatus(u);}}

?附:

?sb.append("\nlocType : ");// 定位類型
? ? ? ? ?sb.append(location.getLocType());
? ? ? ? ?sb.append("\nlatitude : ");// 緯度
? ? ? ? ?sb.append(location.getLatitude());
? ? ? ? ?sb.append("\nlontitude : ");// 經度
? ? ? ? ?sb.append(location.getLongitude());
? ? ? ? ?sb.append("\nradius : ");// 半徑
? ? ? ? ?sb.append(location.getRadius());
? ? ? ? ?sb.append("\nCountryCode : ");// 國家碼
? ? ? ? ?sb.append(location.getCountryCode());
? ? ? ? ?sb.append("\nCountry : ");// 國家名稱
? ? ? ? ?sb.append(location.getCountry());
? ? ? ? ?sb.append("\ncitycode : ");// 城市編碼
? ? ? ? ?sb.append(location.getCityCode());
? ? ? ? ?sb.append("\ncity : ");// 城市
? ? ? ? ?sb.append(location.getCity());
? ? ? ? ?sb.append("\nDistrict : ");// 區
? ? ? ? ?sb.append(location.getDistrict());
? ? ? ? ?sb.append("\nStreet : ");// 街道
? ? ? ? ?sb.append(location.getStreet());
? ? ? ? ?sb.append("\naddr : ");// 地址信息
? ? ? ? ?sb.append(location.getAddrStr());
? ? ? ? ?sb.append("\nDirection(not all devices have value): ");
? ? ? ? ?sb.append(location.getDirection());// 方向
? ? ? ? ?sb.append("\nlocationdescribe: ");
? ? ? ? ?sb.append(location.getLocationDescribe());// 位置語義化信息
? ? ? ? ?sb.append("\nPoi: ");// POI信息
?

private void showMapWithLocationClient() {mLocClient = new LocationClient(this);mLocClient.registerLocationListener(myListener);LocationClientOption option = new LocationClientOption();option.setOpenGps(true);// open gpsoption.setCoorType("bd09ll");//可選,默認0,即僅定位一次,設置定時發起定位請求的間隔需要大于等于1000ms才是有效的/** 定位sdk提供2種定位模式,定時定位和app主動請求定位。* setScanSpan < 1000 則為 app主動請求定位;* setScanSpan >=1000,則為定時定位模式(setScanSpan的值就是定時定位的時間間隔))* 定時定位模式中,定位sdk會按照app設定的時間定位進行位置更新,定時回調定位結果。此種定位模式適用于希望獲得連續定位結果的情況。* 對于單次定位類應用,或者偶爾需要一下位置信息的app,可采用app主動請求定位這種模式。*///option.setScanSpan(2000);//可選,設置是否需要地址信息,默認不需要option.setIsNeedAddress(true);//可選,默認false,設置是否需要位置語義化結果,可以在BDLocation.getLocationDescribe里得到,結果類似于“在北京天安門附近”option.setIsNeedLocationDescribe(true);//設置是否需要返回位置POI信息,可以在BDLocation.getPoiList()中得到數據option.setIsNeedLocationPoiList(true);//在網絡定位時,是否需要設備方向 true:需要 ; false:不需要option.setNeedDeviceDirect(true);//可選,默認true,定位SDK內部是一個SERVICE,并放到了獨立進程,設置是否在stop的時候殺死這個進程,默認不殺死option.setIgnoreKillProcess(false);//可選,默認false,設置是否收集CRASH信息,默認收集option.SetIgnoreCacheException(false);//可選,默認false,設置是否需要過濾gps仿真結果,默認需要option.setEnableSimulateGps(false);option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);mLocClient.setLocOption(option);mLocClient.start(); }

4、運行

?

@Override protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);showMapWithLocationClient(); }

權限

?

<uses-permission android:name="android.permission.ACCESS_GPS" /> <!-- 獲取精確gps位置 --> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- 獲取粗略位置 --> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <!-- 允許程序訪問額外的定位提供者指令獲取模擬定位信息 --> <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> <!-- 網絡鏈接 --> <uses-permission android:name="android.permission.INTERNET" />

?6.0以上版本獲取權限:https://blog.csdn.net/meixi_android/article/details/82114026

?

配置百度服務到manifest

<serviceandroid:name="com.baidu.location.f" android:enabled="true"android:process=":remote"> </service>

配置key

<meta-dataandroid:name="com.baidu.lbsapi.API_KEY"android:value="qn3ZT2xT7yDgbIgkaPooGpDdMjziASZj" />

?

?

谷歌API也可以實現啦:https://blog.csdn.net/meixi_android/article/details/84955589

總結

以上是生活随笔為你收集整理的Android 获取经纬度,地理位置,省市区的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。