电脑是win7,平台使用的是使用的是imobile 9D和android studio,在使用超图的地图进行导航时,地图和定位已经实现了,但是不知道怎么显示当前位置的蓝点。下面是我的代码
private void initialLocation(){
final LocationManager locationManager; //系统定位管理器
String serviceName = Context.LOCATION_SERVICE;
locationManager = (LocationManager)getSystemService(serviceName); //得到系统提供的位置服务
final String provider = LocationManager.NETWORK_PROVIDER; //只能使用NETWOKER_PROVIDER位置进行定位
Criteria criteria = new Criteria(); provider
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(true);
criteria.setBearingRequired(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
Location location = locationManager.getLastKnownLocation(provider);
if(location!=null) {
updateWithNewLocation(location); //调用undateWtihLocation方法进行位置变化的检测
mapControl.getMap().viewEntire();
mapControl.getMap().setCenter(point2ds.getItem(0));
mapControl.getMap().setScale(1 / 15373.046875);
mapControl.zoomTo(18,15);
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 = new CoordSysTranslator();
prjCoordSys = datasource.getDatasets().get(0).getPrjCoordSys(); //获取地图坐标系
point2ds=new Point2Ds();
point2ds.add(new Point2D(lng, lat));
//这行代码实现了将相同坐标系下的地理(经纬度)坐标point2D转化为投影坐标
Boolean isOk=CoordSysTranslator.forward(point2ds,prjCoordSys);
latLongString = "纬度:" + lat + "n经度:\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++){
Address ad = addList.get(i);
latLongString +="n";
latLongString += ad.getCountryName() +";"+ad.getAdminArea()+ ";"+ad.getLocality();
}
}