首先,我为英语道歉,我不知道如何写好英语。
我正在创建一个应在地图上显示用户位置的应用程序。根据文档,我创建了我的监听器并添加了一个覆盖我的位置。
在所有其他 Android 设备中,我的应用程序运行良好,包括 Motorola Defy (MB525),但在 (MB526) 中,它显然没有收到不同的坐标。
public class TesteMapActivity extends MapActivity {
private LocationManager locationManager;
@Override
protected boolean isRouteDisplayed() {
return false;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setAltitudeRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria, true);
locationManager.requestLocationUpdates(provider, 0, 0, locationListener);
MapView mapView = (MapView) findViewById(R.id.mapview);
MapController mapController = mapView.getController();
mapView.setSatellite(false);
mapView.setStreetView(false);
mapView.setBuiltInZoomControls(true);
mapController.setZoom(16);
}
private LocationListener locationListener = new LocationListener() {
int i = 0;
@Override
public void onStatusChanged(String provider, int status, Bundle extras) { }
@Override
public void onProviderEnabled(String provider) { }
@Override
public void onProviderDisabled(String provider) { }
@Override
public void onLocationChanged(Location location) {
i++;
animeTo(location, i);
}
};
public void animeTo(Location location, int i) {
TextView txtCoordenadas = (TextView) findViewById(R.id.txtCoordenadas);
txtCoordenadas.setText(i + " " + location.getLatitude() + ", " + location.getLongitude());
MapView mapView = (MapView) findViewById(R.id.mapview);
MapController mapController = mapView.getController();
if (mapView.getOverlays().size() >= 1) {
mapView.getOverlays().removeAll(mapView.getOverlays());
}
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = getResources().getDrawable(R.drawable.ponto);
OtemizedOverlay itemizedoverlay = new OtemizedOverlay(drawable, TesteMapActivity.this);
Double lat = location.getLatitude() * 1E6;
Double log = location.getLongitude() * 1E6;
GeoPoint point = new GeoPoint(lat.intValue(), log.intValue());
OverlayItem overlayitem = new OverlayItem(point, "Minha Localização", "Latitude: " + lat + " Longitude: " + log);
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
mapController.animateTo(point);
}
}
public class OtemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;
public OtemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
public OtemizedOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
mContext = context;
}
@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
}
谁能帮我?
谢谢你。