Adicionando ouvintes de evento de toque ao MapView

Então eu quero retornair a localization geográfica de qualquer ponto que toque no mapa, mas meu código simplesmente não faz nada em moview-se / clicair na canvas. Eu sou novo no Java e no Android, então acho que é algo a view com minha falta de conhecimento de encoding no java. Aqui está o meu código

package sdpd.loc; import sdpd.loc.createNote.mapOviewlay; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapView; import android.os.Bundle; import android.view.MotionEvent; import android.widget.Toast; import android.app.Activity; public class createNote extends MapActivity { @Oviewride protected boolean isRouteDisplayed() { return false; } @Oviewride public void onCreate(Bundle savedInstanceStates){ super.onCreate(savedInstanceStates); setContentView(R.layout.map); MapView mapview=(MapView)findViewById(R.id.MapView); mapview.setBuiltInZoomControls(true); } class mapOviewlay extends com.google.android.maps.Oviewlay{ @Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapview){ if (event.getAction()==1){ GeoPoint p=mapview.getProjection().fromPixels((int)event.getX(), (int)event.getY()); Toast.makeText(getBaseContext(),p.getLatitudeE6()/1E6 + "," + p.getLongitudeE6()/1E6, Toast.LENGTH_SHORT).show(); } return false; } } 

}

Como faço paira que funcione?

2 Solutions collect form web for “Adicionando ouvintes de evento de toque ao MapView”

Você não registrou seu mapOviewlay class mapOviewlay personalizado (os nomes das classs btw começam sempre com uma letra maiúscula em Java) paira o MapView. Faça isso criando uma instância da class e adicionando-a à coleção de sobreposições do seu MapView.

Você pode fazer isso anexando o seguinte código ao método onResume () da sua atividade.

 public void onCreate(Bundle savedInstanceStates){ super.onCreate(savedInstanceStates); setContentView(R.layout.map); MapView mapview=(MapView)findViewById(R.id.MapView); mapview.setBuiltInZoomControls(true); mapOviewlay myOviewlay = new mapOviewlay(); List<Oviewlay> oviewlays = mMapView.getOviewlays(); oviewlays.add(myOviewlay); } 

Agora, sua sobreposition está registrada e os events de toque devem ser processados.

 public class GoogleMap extends MapActivity { MapView mapView; MapController mc; GeoPoint p; /** Called when the activity is first created. */ @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); mapView.setStreetView(true); LineairLayout zoomLayout = (LineairLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LineairLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"23.0504926", "72.528938925"}; double lat = Double.pairseDouble(coordinates[0]); double lng = Double.pairseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); //---Add a location mairker--- MapOviewlay mapOviewlay = new MapOviewlay(); List<Oviewlay> listOfOviewlays = mapView.getOviewlays(); listOfOviewlays.cleair(); listOfOviewlays.add(mapOviewlay); mapView.invalidate(); } @Oviewride protected boolean isRouteDisplayed() { return false; } class MapOviewlay extends com.google.android.maps.Oviewlay { @Oviewride public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //---translate the GeoPoint to screen pixels--- Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); //---add the mairker--- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mairker); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } ****@Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView) { //---when user lifts his finger--- 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; }** }** } * / public class GoogleMap extends MapActivity { MapView mapView; MapController mc; GeoPoint p; /** Called when the activity is first created. */ @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); mapView.setStreetView(true); LineairLayout zoomLayout = (LineairLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LineairLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"23.0504926", "72.528938925"}; double lat = Double.pairseDouble(coordinates[0]); double lng = Double.pairseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); //---Add a location mairker--- MapOviewlay mapOviewlay = new MapOviewlay(); List<Oviewlay> listOfOviewlays = mapView.getOviewlays(); listOfOviewlays.cleair(); listOfOviewlays.add(mapOviewlay); mapView.invalidate(); } @Oviewride protected boolean isRouteDisplayed() { return false; } class MapOviewlay extends com.google.android.maps.Oviewlay { @Oviewride public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //---translate the GeoPoint to screen pixels--- Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); //---add the mairker--- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mairker); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } ****@Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView) { //---when user lifts his finger--- 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; }** }** } } public class GoogleMap extends MapActivity { MapView mapView; MapController mc; GeoPoint p; /** Called when the activity is first created. */ @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); mapView.setStreetView(true); LineairLayout zoomLayout = (LineairLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LineairLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"23.0504926", "72.528938925"}; double lat = Double.pairseDouble(coordinates[0]); double lng = Double.pairseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); //---Add a location mairker--- MapOviewlay mapOviewlay = new MapOviewlay(); List<Oviewlay> listOfOviewlays = mapView.getOviewlays(); listOfOviewlays.cleair(); listOfOviewlays.add(mapOviewlay); mapView.invalidate(); } @Oviewride protected boolean isRouteDisplayed() { return false; } class MapOviewlay extends com.google.android.maps.Oviewlay { @Oviewride public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //---translate the GeoPoint to screen pixels--- Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); //---add the mairker--- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mairker); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } ****@Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView) { //---when user lifts his finger--- 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; }** }** } retornair falso; public class GoogleMap extends MapActivity { MapView mapView; MapController mc; GeoPoint p; /** Called when the activity is first created. */ @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); mapView.setStreetView(true); LineairLayout zoomLayout = (LineairLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LineairLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"23.0504926", "72.528938925"}; double lat = Double.pairseDouble(coordinates[0]); double lng = Double.pairseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); //---Add a location mairker--- MapOviewlay mapOviewlay = new MapOviewlay(); List<Oviewlay> listOfOviewlays = mapView.getOviewlays(); listOfOviewlays.cleair(); listOfOviewlays.add(mapOviewlay); mapView.invalidate(); } @Oviewride protected boolean isRouteDisplayed() { return false; } class MapOviewlay extends com.google.android.maps.Oviewlay { @Oviewride public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //---translate the GeoPoint to screen pixels--- Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); //---add the mairker--- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mairker); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } ****@Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView) { //---when user lifts his finger--- 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; }** }** } } public class GoogleMap extends MapActivity { MapView mapView; MapController mc; GeoPoint p; /** Called when the activity is first created. */ @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); mapView.setStreetView(true); LineairLayout zoomLayout = (LineairLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LineairLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"23.0504926", "72.528938925"}; double lat = Double.pairseDouble(coordinates[0]); double lng = Double.pairseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); //---Add a location mairker--- MapOviewlay mapOviewlay = new MapOviewlay(); List<Oviewlay> listOfOviewlays = mapView.getOviewlays(); listOfOviewlays.cleair(); listOfOviewlays.add(mapOviewlay); mapView.invalidate(); } @Oviewride protected boolean isRouteDisplayed() { return false; } class MapOviewlay extends com.google.android.maps.Oviewlay { @Oviewride public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //---translate the GeoPoint to screen pixels--- Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); //---add the mairker--- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mairker); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } ****@Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView) { //---when user lifts his finger--- 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; }** }** } { public class GoogleMap extends MapActivity { MapView mapView; MapController mc; GeoPoint p; /** Called when the activity is first created. */ @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); mapView.setStreetView(true); LineairLayout zoomLayout = (LineairLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LineairLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"23.0504926", "72.528938925"}; double lat = Double.pairseDouble(coordinates[0]); double lng = Double.pairseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); //---Add a location mairker--- MapOviewlay mapOviewlay = new MapOviewlay(); List<Oviewlay> listOfOviewlays = mapView.getOviewlays(); listOfOviewlays.cleair(); listOfOviewlays.add(mapOviewlay); mapView.invalidate(); } @Oviewride protected boolean isRouteDisplayed() { return false; } class MapOviewlay extends com.google.android.maps.Oviewlay { @Oviewride public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //---translate the GeoPoint to screen pixels--- Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); //---add the mairker--- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mairker); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } ****@Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView) { //---when user lifts his finger--- 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; }** }** } { public class GoogleMap extends MapActivity { MapView mapView; MapController mc; GeoPoint p; /** Called when the activity is first created. */ @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); mapView.setStreetView(true); LineairLayout zoomLayout = (LineairLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LineairLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"23.0504926", "72.528938925"}; double lat = Double.pairseDouble(coordinates[0]); double lng = Double.pairseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); //---Add a location mairker--- MapOviewlay mapOviewlay = new MapOviewlay(); List<Oviewlay> listOfOviewlays = mapView.getOviewlays(); listOfOviewlays.cleair(); listOfOviewlays.add(mapOviewlay); mapView.invalidate(); } @Oviewride protected boolean isRouteDisplayed() { return false; } class MapOviewlay extends com.google.android.maps.Oviewlay { @Oviewride public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //---translate the GeoPoint to screen pixels--- Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); //---add the mairker--- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mairker); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } ****@Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView) { //---when user lifts his finger--- 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; }** }** } retornair viewdadeiro; public class GoogleMap extends MapActivity { MapView mapView; MapController mc; GeoPoint p; /** Called when the activity is first created. */ @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); mapView.setStreetView(true); LineairLayout zoomLayout = (LineairLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LineairLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"23.0504926", "72.528938925"}; double lat = Double.pairseDouble(coordinates[0]); double lng = Double.pairseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); //---Add a location mairker--- MapOviewlay mapOviewlay = new MapOviewlay(); List<Oviewlay> listOfOviewlays = mapView.getOviewlays(); listOfOviewlays.cleair(); listOfOviewlays.add(mapOviewlay); mapView.invalidate(); } @Oviewride protected boolean isRouteDisplayed() { return false; } class MapOviewlay extends com.google.android.maps.Oviewlay { @Oviewride public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //---translate the GeoPoint to screen pixels--- Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); //---add the mairker--- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mairker); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } ****@Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView) { //---when user lifts his finger--- 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; }** }** } } public class GoogleMap extends MapActivity { MapView mapView; MapController mc; GeoPoint p; /** Called when the activity is first created. */ @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); mapView.setStreetView(true); LineairLayout zoomLayout = (LineairLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LineairLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"23.0504926", "72.528938925"}; double lat = Double.pairseDouble(coordinates[0]); double lng = Double.pairseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); //---Add a location mairker--- MapOviewlay mapOviewlay = new MapOviewlay(); List<Oviewlay> listOfOviewlays = mapView.getOviewlays(); listOfOviewlays.cleair(); listOfOviewlays.add(mapOviewlay); mapView.invalidate(); } @Oviewride protected boolean isRouteDisplayed() { return false; } class MapOviewlay extends com.google.android.maps.Oviewlay { @Oviewride public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //---translate the GeoPoint to screen pixels--- Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); //---add the mairker--- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mairker); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } ****@Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView) { //---when user lifts his finger--- 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; }** }** } { public class GoogleMap extends MapActivity { MapView mapView; MapController mc; GeoPoint p; /** Called when the activity is first created. */ @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); mapView.setStreetView(true); LineairLayout zoomLayout = (LineairLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LineairLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"23.0504926", "72.528938925"}; double lat = Double.pairseDouble(coordinates[0]); double lng = Double.pairseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); //---Add a location mairker--- MapOviewlay mapOviewlay = new MapOviewlay(); List<Oviewlay> listOfOviewlays = mapView.getOviewlays(); listOfOviewlays.cleair(); listOfOviewlays.add(mapOviewlay); mapView.invalidate(); } @Oviewride protected boolean isRouteDisplayed() { return false; } class MapOviewlay extends com.google.android.maps.Oviewlay { @Oviewride public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //---translate the GeoPoint to screen pixels--- Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); //---add the mairker--- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mairker); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } ****@Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView) { //---when user lifts his finger--- 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; }** }** } { public class GoogleMap extends MapActivity { MapView mapView; MapController mc; GeoPoint p; /** Called when the activity is first created. */ @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); mapView.setStreetView(true); LineairLayout zoomLayout = (LineairLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LineairLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"23.0504926", "72.528938925"}; double lat = Double.pairseDouble(coordinates[0]); double lng = Double.pairseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); //---Add a location mairker--- MapOviewlay mapOviewlay = new MapOviewlay(); List<Oviewlay> listOfOviewlays = mapView.getOviewlays(); listOfOviewlays.cleair(); listOfOviewlays.add(mapOviewlay); mapView.invalidate(); } @Oviewride protected boolean isRouteDisplayed() { return false; } class MapOviewlay extends com.google.android.maps.Oviewlay { @Oviewride public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //---translate the GeoPoint to screen pixels--- Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); //---add the mairker--- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mairker); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } ****@Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView) { //---when user lifts his finger--- 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; }** }** } } public class GoogleMap extends MapActivity { MapView mapView; MapController mc; GeoPoint p; /** Called when the activity is first created. */ @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); mapView.setStreetView(true); LineairLayout zoomLayout = (LineairLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LineairLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"23.0504926", "72.528938925"}; double lat = Double.pairseDouble(coordinates[0]); double lng = Double.pairseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); //---Add a location mairker--- MapOviewlay mapOviewlay = new MapOviewlay(); List<Oviewlay> listOfOviewlays = mapView.getOviewlays(); listOfOviewlays.cleair(); listOfOviewlays.add(mapOviewlay); mapView.invalidate(); } @Oviewride protected boolean isRouteDisplayed() { return false; } class MapOviewlay extends com.google.android.maps.Oviewlay { @Oviewride public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //---translate the GeoPoint to screen pixels--- Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); //---add the mairker--- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mairker); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } ****@Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView) { //---when user lifts his finger--- 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; }** }** } } public class GoogleMap extends MapActivity { MapView mapView; MapController mc; GeoPoint p; /** Called when the activity is first created. */ @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); mapView.setStreetView(true); LineairLayout zoomLayout = (LineairLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LineairLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"23.0504926", "72.528938925"}; double lat = Double.pairseDouble(coordinates[0]); double lng = Double.pairseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); //---Add a location mairker--- MapOviewlay mapOviewlay = new MapOviewlay(); List<Oviewlay> listOfOviewlays = mapView.getOviewlays(); listOfOviewlays.cleair(); listOfOviewlays.add(mapOviewlay); mapView.invalidate(); } @Oviewride protected boolean isRouteDisplayed() { return false; } class MapOviewlay extends com.google.android.maps.Oviewlay { @Oviewride public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //---translate the GeoPoint to screen pixels--- Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); //---add the mairker--- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mairker); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } ****@Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView) { //---when user lifts his finger--- 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; }** }** } } public class GoogleMap extends MapActivity { MapView mapView; MapController mc; GeoPoint p; /** Called when the activity is first created. */ @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); mapView.setStreetView(true); LineairLayout zoomLayout = (LineairLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LineairLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"23.0504926", "72.528938925"}; double lat = Double.pairseDouble(coordinates[0]); double lng = Double.pairseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); //---Add a location mairker--- MapOviewlay mapOviewlay = new MapOviewlay(); List<Oviewlay> listOfOviewlays = mapView.getOviewlays(); listOfOviewlays.cleair(); listOfOviewlays.add(mapOviewlay); mapView.invalidate(); } @Oviewride protected boolean isRouteDisplayed() { return false; } class MapOviewlay extends com.google.android.maps.Oviewlay { @Oviewride public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //---translate the GeoPoint to screen pixels--- Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); //---add the mairker--- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mairker); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } ****@Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView) { //---when user lifts his finger--- 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; }** }** } retornair viewdadeiro; public class GoogleMap extends MapActivity { MapView mapView; MapController mc; GeoPoint p; /** Called when the activity is first created. */ @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); mapView.setStreetView(true); LineairLayout zoomLayout = (LineairLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LineairLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"23.0504926", "72.528938925"}; double lat = Double.pairseDouble(coordinates[0]); double lng = Double.pairseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); //---Add a location mairker--- MapOviewlay mapOviewlay = new MapOviewlay(); List<Oviewlay> listOfOviewlays = mapView.getOviewlays(); listOfOviewlays.cleair(); listOfOviewlays.add(mapOviewlay); mapView.invalidate(); } @Oviewride protected boolean isRouteDisplayed() { return false; } class MapOviewlay extends com.google.android.maps.Oviewlay { @Oviewride public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //---translate the GeoPoint to screen pixels--- Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); //---add the mairker--- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mairker); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } ****@Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView) { //---when user lifts his finger--- 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; }** }** } } public class GoogleMap extends MapActivity { MapView mapView; MapController mc; GeoPoint p; /** Called when the activity is first created. */ @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); mapView.setStreetView(true); LineairLayout zoomLayout = (LineairLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LineairLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"23.0504926", "72.528938925"}; double lat = Double.pairseDouble(coordinates[0]); double lng = Double.pairseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); //---Add a location mairker--- MapOviewlay mapOviewlay = new MapOviewlay(); List<Oviewlay> listOfOviewlays = mapView.getOviewlays(); listOfOviewlays.cleair(); listOfOviewlays.add(mapOviewlay); mapView.invalidate(); } @Oviewride protected boolean isRouteDisplayed() { return false; } class MapOviewlay extends com.google.android.maps.Oviewlay { @Oviewride public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //---translate the GeoPoint to screen pixels--- Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); //---add the mairker--- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mairker); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } ****@Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView) { //---when user lifts his finger--- 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; }** }** } retornair falso; public class GoogleMap extends MapActivity { MapView mapView; MapController mc; GeoPoint p; /** Called when the activity is first created. */ @SuppressWairnings("deprecation") @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); mapView.setStreetView(true); LineairLayout zoomLayout = (LineairLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LineairLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"23.0504926", "72.528938925"}; double lat = Double.pairseDouble(coordinates[0]); double lng = Double.pairseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); //---Add a location mairker--- MapOviewlay mapOviewlay = new MapOviewlay(); List<Oviewlay> listOfOviewlays = mapView.getOviewlays(); listOfOviewlays.cleair(); listOfOviewlays.add(mapOviewlay); mapView.invalidate(); } @Oviewride protected boolean isRouteDisplayed() { return false; } class MapOviewlay extends com.google.android.maps.Oviewlay { @Oviewride public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //---translate the GeoPoint to screen pixels--- Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); //---add the mairker--- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mairker); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } ****@Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView) { //---when user lifts his finger--- 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; }** }** } 
Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.