坐标转换,返回的flase,转换不成功不知道为什么
private void initView() {
m_workSpace = new Workspace();
m_mapControl = map_view.getMapControl();
m_mapControl.getMap().setWorkspace(m_workSpace);//将地图显示控件和工作空间关联
DatasourceConnectionInfo info = new DatasourceConnectionInfo();
info.setAlias("TianDitu1");//设置数据源别名
info.setEngineType(EngineType.OGC);//设置引擎类型
info.setDriver("WMTS");//设置驱动名称
String url = "http://t0.tianditu.gov.cn/img_c/wmts?tk=3755380e2e68e91d949922da5ab106e";//设置地图服务地址
info.setServer(url);
Datasources datasources = m_workSpace.getDatasources();//打开数据源
ds = datasources.open(info);
m_mapControl.getMap().getLayers().add(ds.getDatasets().get(0), true);//添加到地图窗口中
Log.d("qewqewqewq", String.valueOf(m_mapControl.getMap().getCenter()));
final LocationManager locationManager;
String serviceName = Context.LOCATION_SERVICE;
locationManager = (LocationManager) getSystemService(serviceName); //得到系统提供的位置服务
final String provider = LocationManager.NETWORK_PROVIDER; //只能使用NETWOKER_PROVIDER位置进行定位
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(true);
criteria.setBearingRequired(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
Location location = locationManager.getLastKnownLocation(provider);
if(location!=null) {
updateWithNewLocation(location); //调用undateWtihLocation方法进行位置变化的检测
m_mapControl.getMap().viewEntire();
m_mapControl.getMap().setCenter(point2ds.getItem(0));
m_mapControl.getMap().setScale(1 / 15373.046875);
m_mapControl.zoomTo(18,15);
m_mapControl.getMap().refresh();
}
private void updateWithNewLocation(Location location) {
double lat = 0;
double lng = 0;
String latLongString;
if (location != null) {
lat = location.getLatitude(); //得到当前位置的经纬度
lng = location.getLongitude();
//在同一地理坐标系下,该方法用于将指定的Point2Ds 类型的点对象的投影坐标转换到地理坐标
CoordSysTranslator coordSysTranslator=new CoordSysTranslator();
//获取地图坐标系
PrjCoordSys prjCoordSys = m_mapControl.getMap().getPrjCoordSys();
// double aa[] = MillierConvertion(lat,lng);
point2ds = new Point2Ds();
point2ds.add(new Point2D(lng, lat));
//这行代码实现了将相同坐标系下的地理(经纬度)坐标point2D转化为投影坐标
Boolean isOk = CoordSysTranslator.forward(point2ds, prjCoordSys);
// Log.d("point2d", String.valueOf(isOk));
latLongString = "纬度:" + lat + "\n经度:" + lng;
} else {
latLongString = "无法获取地理信息";
}
List<Address> addList = null;
Geocoder ge = new Geocoder(this);
try {
addList = ge.getFromLocation(lat, lng, 1);
} catch (IOException e) {
e.printStackTrace();
}
if (addList != null && addList.size() > 0) {
for (int i = 0; i < addList.size(); i++) {
android.location.Address ad = addList.get(i);
latLongString += "\n";
latLongString += ad.getCountryName() + ";" + ad.getAdminArea() + ";" + ad.getLocality();
Log.d("zzk",latLongString);
}
}
}