导航:首页 > 源码编译 > 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