導航:首頁 > 源碼編譯 > android地圖定位源碼

android地圖定位源碼

發布時間:2025-03-05 03:25:26

android開發中百度地圖的定位為什麼總是北京,不是自己的位置

給,對照一下
可能的問題:1.用虛擬機,虛擬機定位就是在北京。
2.手機(或虛擬機)是否開啟了GPS功能

------------------------------
public class MainActivity extends AppCompatActivity {

MapView mMapView = null;
private BaiMap mBaiDuMap;
public LocationClient mLocationClient;
// public BDLocationListener myListener = new MyLocationListener();
public MyLocationListener myListener = new MyLocationListener();
private BitmapDescriptor mCurrentMarker;
private MyLocationConfiguration.LocationMode mCurrentMode;

// 經緯度
private TextView tvJingDu;
// 緯度
private TextView tvWeiDu;
// 高度
private TextView tvGaoDu;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SDKInitializer.initialize(getApplicationContext());
setContentView(R.layout.activity_main);

// 經緯度TextView 初始化
tvJingDu = (TextView) findViewById(R.id.tv_jing_);
tvWeiDu = (TextView) findViewById(R.id.tv_wei_);
tvGaoDu = (TextView) findViewById(R.id.tv_gao_);

//===================================
// 普通模式
mCurrentMode = MyLocationConfiguration.LocationMode.COMPASS;

// TODO
// mCurrentMarker = BitmapDescriptorFactory.fromResource(R.drawable.dingwei);
mCurrentMarker = null;

// 找到地圖控制項
mMapView = (MapView) findViewById(R.id.bmapView);
mBaiDuMap = mMapView.getMap();// 獲取地圖

mBaiDuMap.setMapType(BaiMap.MAP_TYPE_NORMAL);// 設置地圖模式為普通模式

// 開啟定點陣圖層
mBaiDuMap.setMyLocationEnabled(true);
mLocationClient = new LocationClient(this); // 定位用到一個類
mLocationClient.registerLocationListener(myListener);// 注冊監聽

// TODO
mBaiDuMap.setMyLocationConfigeration(new MyLocationConfiguration(
mCurrentMode, true, mCurrentMarker, R.color.myBlue, Color.YELLOW
));

// LocationClientOption類用來設置SDK的位置方式
LocationClientOption option = new LocationClientOption();//以下是給定位設置參數
option.setOpenGps(true); // 打開gps
option.setCoorType("bd09ll"); // 設置坐標類型
option.setScanSpan(2000);
mLocationClient.setLocOption(option);
mLocationClient.start();

}

boolean isFirstLoc = true; // 是否首次定位

// 3.網路位置監聽
public class MyLocationListener implements BDLocationListener {

@Override
public void onReceiveLocation(BDLocation location) {
Log.i("監聽被執行了", "監聽被執行了");

if (location == null || mMapView == null) {
return;
}

// // 定位結果
// StringBuffer sb = new StringBuffer(256);
// StringBuffer sb1 = new StringBuffer(256);
// StringBuffer sb2 = new StringBuffer(256);
// // 經度
// String jd = sb.append(location.getLongitude()).toString();
// tvJingDu.setText("" + jd);
// Log.i("經度", "" + jd);
// // 緯度
// String wd = sb1.append(location.getLatitude()).toString();
// tvWeiDu.setText("" + sb1);
// Log.i("緯度", "" + wd);
//
// String gao = sb.append(location.getAltitude()).toString();
// tvGaoDu.setText("" + gao);
// 經度
double d1 = location.getLongitude();
String s1 = "" + d1;
tvWeiDu.setText(s1);
Log.i("經度", "" + s1);
// 緯度
double d2 = location.getLatitude();
Log.i("TGA", "d2" + d2);
String s2 = "" + d2;
tvJingDu.setText(s2);
Log.i("緯度", "" + s2);

MyLocationData locData = new MyLocationData.Builder()
.accuracy(location.getRadius())
// 此處設置開發者獲取到的方向信息,順時針0-360
.direction(0).latitude(location.getLatitude())
.longitude(location.getLongitude()).build();
mBaiDuMap.setMyLocationData(locData);

if (isFirstLoc) {
isFirstLoc = false;
LatLng ll = new LatLng(location.getLatitude(),
location.getLongitude());
MapStatus.Builder builder = new MapStatus.Builder();
// 縮放的等級 12.0f
builder.target(ll).zoom(18.0f);
mBaiDuMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
}
Log.i("MyLocationListener被執行了!", "onReceiveLocation");

}

@Override
public void onConnectHotSpotMessage(String s, int i) {

}
}

// 結束方法

@Override
protected void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}

@Override
protected void onResume() {
super.onResume();
mMapView.onResume();
}

@Override
protected void onPause() {
super.onPause();
mMapView.onPause();
}
}

❷ android 怎麼確定高德地圖導航

如果是想在自己的app自帶導航界面,就接入高德地圖sdk。

如果想從自己app開啟高德地圖app導航,那就上代碼:

//高德地圖,起點就是定位點

//終點是LatLngll=newLatLng("你的緯度latitude","你的經度longitude");

publicvoidstartNaviGao(){

if(isAvilible(getContext(),"com.autonavi.minimap")){

try{

//sourceApplication

Intentintent=Intent.getIntent("androidamap://navi?sourceApplication=公司的名稱(隨意寫)&poiname=我的目的地&lat="+ll.latitude+"&lon="+ll.longitude+"&dev=0");

startActivity(intent);

}catch(URISyntaxExceptione){

e.printStackTrace();

}

}else{

ToastUtil.showToast("您尚未安裝高德地圖或地圖版本過低");

}

}


❸ android (uniapp)引入高德地圖,實時定位(精度)

在使用uniapp進行android開發時,定位功能可以通過兩種方式實現:一是直接連接手機進行測試,二是運行在自定義基座上。


1. 直接連接手機測試:無需特別申請高德地圖的key,代碼中也不需要引入,盡管如此,定位功能依然可以精確實現。這可能是因為uniapp的安卓集成版本自帶了高德地圖支持,uni.getlocation方法就能獲取定位。


2. 自定義基座測試則有所不同:必須在高德開放平台獲取對應的安卓key,這與小程序的key和ios的key是分開申請的。在manifest.json文件中配置是必要的,否則可能會出現簽名不一致的錯誤。


在定位精度上,uni.getlocation、plus.geolocation.watchPosition和小程序的amapPlugin.getRegeo方法在連接手機時表現相近,都非常精確。然而,當在自定義基座上測試時,如果未正確配置maps,可能會導致定位出現誤差,尤其是在使用小程序key和amaps-wx.js時,定位精度會有500米左右的偏差。


最終,定位問題的解決在於確保在manifest.json中正確配置了appid、key以及包名。只有這樣,無論是在連接手機還是自定義基座上,定位都能達到預期的精度。

❹ 怎麼在android百度地圖通過經緯度來定位並且顯示出地圖位置

在onLocationChanged方法里獲得自己當前的坐標然後方法里寫mSearch.reverseGeocode(newGeoPoint((int)(location.getLatitude()*1e6),(int)(location.getLongitude()*1e6)));然後再通過代碼實行這個方法功能{publicvoidonGetAddrResult(MKAddrInforesult,interror){MKGeocoderAddressComponentkk=result.addressComponents;Stringcity=kk.city;}}city就是你所在城市

閱讀全文

與android地圖定位源碼相關的資料

熱點內容
命令式介面 瀏覽:399
電腦伺服器域名地址怎麼查 瀏覽:340
什麼行業要用編程 瀏覽:297
三洋立風櫃壓縮機 瀏覽:296
微拍app為什麼下載不了了 瀏覽:257
非常好的期貨5分鍾公式源碼 瀏覽:4
linuxcentos7安裝 瀏覽:691
華為網盤文件夾加密 瀏覽:74
安卓手機什麼真人游戲好玩 瀏覽:772
崑山加密軟體需求 瀏覽:270
蘋果照片壓縮包怎麼打開 瀏覽:796
檢測溫濕度和二氧化碳的單片機 瀏覽:964
安卓手機雨滴怎麼隱藏 瀏覽:587
pdf文件轉換器word 瀏覽:987
vscodepython模塊方法 瀏覽:344
如何知道伺服器有什麼漏洞 瀏覽:902
java電商訂單支付源碼 瀏覽:102
android手機滑鼠 瀏覽:465
php支付項目經驗 瀏覽:931
中國人民銀行在哪裡下載app 瀏覽:562