Я создаю приложение Google Map. Я хочу получить адрес точки, когда я нажимаю на экран, но когда я нажимаю на экран, он не запускается, ничего не происходит. Как я могу это исправить?
Это мой код:
package app.googlemap;
public class GoogleMapActivity extends MapActivity {
MapView mapView;
View zoomView;
MapController mc;
GeoPoint p;
private List<Overlay> mapOverlays;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView=(MapView)findViewById(R.id.simple_map);
LinearLayout zoomLayout=(LinearLayout)findViewById(R.id.zoom);
zoomView = mapView.getZoomControls();
zoomLayout.addView(zoomView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
mapView.setTraffic(true);
String coordinates[]={"21.036074","105.833636"};
double latiTude=Double.parseDouble(coordinates[0]);
double longiTude=Double.parseDouble(coordinates[1]);
p=new GeoPoint((int)(latiTude*1E6), (int)(longiTude*1e6));
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
mc=mapView.getController();
mc.animateTo(p);
mc.setZoom(17);
mapView.invalidate();
}
public void draw(GeoPoint g,int a ){
mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(a);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable);
OverlayItem overlayitem = new OverlayItem(p, "", "");
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
}
public class MapOverlay extends com.google.android.maps.Overlay{
private Bitmap bmp;
public boolean draw(Canvas canvas, MapView mapView, boolean shadow ,long when){
super.draw(canvas, mapView, shadow);
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
bmp=BitmapFactory.decodeResource(getResources(), R.drawable.t5);
canvas.drawBitmap(bmp, screenPts.x,screenPts.y-50, null);
return true;
}
@Override
public boolean onTouchEvent(MotionEvent event, MapView mapView)
{
if (event.getAction() == 1) {
GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(),
(int) event.getY());
Geocoder geoCoder = new Geocoder(
getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(
p.getLatitudeE6() / 1E6,
p.getLongitudeE6() / 1E6, 1);
String add = "";
if (addresses.size() > 0)
{
for (int i=0; i<addresses.get(0).getMaxAddressLineIndex(); i++)
add += addresses.get(0).getAddressLine(i) + "\n";
}
Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT).show();
}
catch (IOException e) {
e.printStackTrace();
}
return true;
}
else
return false;
}
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}