我在应用程序中使用定位服务。如果我发送经度和纬度通过DDMS模拟器,蓝点动画到那里。但是,如果我关闭应用程序,重新启动,蓝点似乎不似乎。如果你看到蓝点,你必须发送新的经度和纬度。我想每次应用程序启动时都显示蓝点.
我能做些什么?
onCreate:
mc = mapView.getController();
mapView.setBuiltInZoomControls(true);
mc.setZoom(15);
myLocOverlay = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(myLocOverlay);
myLocOverlay.runOnFirstFix(new Runnable() {
public void run() {
mc.animateTo(myLocOverlay.getMyLocation());
}
});
mapView.postInvalidate();
lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
provider = lm.getBestProvider(criteria, false);
Location location = lm.getLastKnownLocation(provider);
if (location != null) {
onLocationChanged(location);
}onLocationChanged(地点)
String PK="";
double lat = location.getLatitude();
double lng = location.getLongitude();
Geocoder gc = new Geocoder(this,Locale.getDefault());
try{
List<Address> adresler = gc.getFromLocation(lat, lng, 1);
StringBuilder sb = new StringBuilder();
if(adresler.size()>0){
Address adres = adresler.get(0);
boolean sayi = false;
for(int i=0;i<adres.getMaxAddressLineIndex();i++){
if(i!=2){
sb.append(adres.getAddressLine(i)).append("\n");
}
else{
String full = adres.getAddressLine(i).toString();
char chars[] = full.toCharArray();
for(int k=0;k<chars.length;k++){
sayi = Character.isDigit(chars[k]);
if(sayi){
PK=PK+chars[k];
}
}
}
}
adresString = sb.toString();
new gpsYerBilgisiAS(PK).execute();
}
}
catch(IOException e){
}
}onResume和onPause
@Override
protected void onResume() {
super.onResume();
lm.requestLocationUpdates(provider, 400, 1, this);
myLocOverlay.enableMyLocation();
}
@Override
protected void onPause() {
super.onPause();
lm.removeUpdates(this);
myLocOverlay.disableMyLocation();
}发布于 2012-08-16 09:22:18
在模拟器中,每次调用onLocationChanged方法时都必须发送位置。在设备上,如果GPS是打开的,它就会自动完成。但我只会显示“蓝点”,当你的设备接收到的位置数据通过GPS或网络。
发布于 2012-08-16 08:45:13
让你的onResume()像这样:
protected void onResume() {
....
myLocOverlay = new MyLocationOverlay(this, mapView);
myLocOverlay.enableMyLocation();
mapView.getOverlays().add(myLocOverlay);
myLocOverlay.runOnFirstFix(new Runnable() {
public void run() {
mc.animateTo(myLocOverlay.getMyLocation());
}
});
....
}它会以你想要的方式运作。这是我目前在我自己的应用程序中使用的方式。
https://stackoverflow.com/questions/11983328
复制相似问题