我正在做android 地图应用程序,我需要在中心使用固定标记拖动地图。
下面是我的代码。它运行良好。添加了我需要对其进行搜索功能。即当我在顶部编辑框上键入地址时,该位置应位于固定定位标记下。
我怎么能这样做?
我的代码:
public class MapDragActivity extends MapActivity implements LocationListener{
String pinadd="";
private MapView map=null;
private LocationManager locationManager;
GeoPoint myLocation;
/** Called when the activity is first created. */
@SuppressWarnings("static-access")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maplayout);
map=(MapView)findViewById(R.id.map);
map.setBuiltInZoomControls(true);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null)
plotLocation(location);
else
locationManager.requestLocationUpdates(
locationManager.NETWORK_PROVIDER, 500L, 250.0f, this);
}
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
if (location != null)
plotLocation(location);
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@SuppressWarnings("static-access")
@Override
public void onResume() {
super.onResume();
locationManager.requestLocationUpdates(
locationManager.NETWORK_PROVIDER, 1000L, 500.0f, this);
}
@Override
public void onPause() {
super.onPause();
locationManager.removeUpdates(this);
}
@Override
public void onDestroy(){
locationManager.removeUpdates(this);
super.onDestroy();
}
@Override
public boolean dispatchTouchEvent(MotionEvent event){
boolean result = super.dispatchTouchEvent(event);
if (event.getAction() == MotionEvent.ACTION_UP){
Projection projection = map.getProjection();
int y = map.getHeight() / 2;
int x = map.getWidth() / 2;
GeoPoint geoPoint = projection.fromPixels(x, y);
Log.v("Latitude & Logitude", geoPoint.getLatitudeE6() +"//"+geoPoint.getLongitudeE6());
}
return result;
}
double roundTwoDecimals(double d){
DecimalFormat twoDForm = new DecimalFormat("#.######");
return Double.valueOf(twoDForm.format(d));
}
public void plotLocation(Location location) {
GeoPoint point = new GeoPoint(
(int) (roundTwoDecimals(location.getLatitude()) * 1E6),
(int) (roundTwoDecimals(location.getLongitude()) * 1E6));
myLocation = point;
map.getController().animateTo(point);
map.getController().setCenter(point);
zoomToMyLocation();
}
private void zoomToMyLocation() {
if (myLocation != null) {
map.getController().setZoom(18);
map.getController().animateTo(myLocation);
}
}
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
谢谢。