Android中百度地图计算MapView任意位置的经纬度

SDK版本:3.2.0

百度地图sdk只提供了直接获取MapView中心点经纬度的方法,求其他地方的经纬度要自己算。获取任一点经纬度的方法为:

mMap.getProjection().fromScreenLocation(new Point(x, y));

计算的准不准看一下就知道啦~这里用直接获取到的中心点的经纬度和通过上面方法获取到的对比一下。

获取中心点经纬度的方法为:

mMap = mMapView.getMap();mMapStatus = mMap.getMapStatus();LatLng center = mMapStatus.target;中心点在MapView上的位置:Point point = mapStatus.targetScreen;

拿到中心点在MapView上的位置就可以算出MapView的宽度和高度了

String str = "Center:\nlat:" + mapStatus.target.latitude;str = str + "\nlng:" + mapStatus.target.longitude;str = str + "\n位置:\nx:" + mapStatus.targetScreen.x;str = str + "\ny:" + mapStatus.targetScreen.y;Point point = mapStatus.targetScreen;LatLng cal = mMap.getProjection().fromScreenLocation(new Point(mapStatus.targetScreen.x,mapStatus.targetScreen.y));str = str + "\n转换标:\nlat:" + cal.latitude;str = str + "\nlng:" + cal.longitude;str = str + "\n误差:\nlat:" + (cal.latitude – mapStatus.target.latitude);str = str + "\nlng:" + (cal.longitude – mapStatus.target.longitude);Toast.makeText(getApplicationContext(),str,Toast.LENGTH_LONG).show();结果显示误差一直都是0.0哦!很准!

,三人一条心,黄土变成金。

Android中百度地图计算MapView任意位置的经纬度

相关文章:

你感兴趣的文章:

标签云: