public class Mapa extends MapActivity{
protected static Context MainActivity = null;
public CapaTap itemizedOverlay;
public Drawable defaultMarker;
Drawable gpsMarker;
ArrayItemizedOverlay gpsItemizedOverlay;
ArrayList<SQLloja> listaLoja;
Double altitude;
Double longitude;
Integer zoom;
LocationManager lm;
MapView mapView ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
listaLoja = new loadDatabase().execute().get();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Action Bar is the bar on the top of each activity !
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
Intent intent = getIntent();
zoom = (Integer) intent.getSerializableExtra("zoom");
altitude = (Double) intent.getSerializableExtra("altitude");
longitude = (Double) intent.getSerializableExtra("longitude");
MainActivity=this;
gpsMarker = getResources().getDrawable(R.drawable.mapsredpoiicon);
defaultMarker = getResources().getDrawable(R.drawable.markergold);
itemizedOverlay = new CapaTap(defaultMarker, MainActivity);
gpsItemizedOverlay = new ArrayItemizedOverlay(gpsMarker);
for(SQLloja loja : listaLoja){
String informacoesLoja = "Rua : "+loja.getMorada()+"\nC.P. : "+loja.getCodigo_postal()+"\nTel. : "+loja.getTelefone();
itemizedOverlay.addItem(new OverlayItem(new GeoPoint(loja.getLatitude(), loja.getLongitude()),"Loja Cidadao "+loja.getNome(),informacoesLoja));
}
mapView = new MapView(this, new MapnikTileDownloader());
mapView.setClickable(true);
mapView.setBuiltInZoomControls(true);
//mapView.setTextScale(4f);
setContentView(mapView);
// Ajustar el zoom y el centro del mapa
mapView.setCenter(new GeoPoint(altitude, longitude));
mapView.zoom((byte) 2, 0);
mapView.getOverlays().add(itemizedOverlay);
Log.d("GPS3",Integer.toString(mapView.getOverlays().size()));
mapView.getController().setZoom(zoom);
// MapScaleBar
MapScaleBar scaleBar = mapView.getMapScaleBar();
scaleBar.setShowMapScaleBar(true);
/*---------------*/
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new MyLocationListener();
lm.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, locationListener);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10, 20, locationListener);
}
public class CapaTap extends ArrayItemizedOverlay {
private final Context context;
CapaTap(Drawable defaultMarker, Context context) {
super(defaultMarker);
this.context = context;
}
@Override
protected boolean onTap(final int index) {
OverlayItem item = createItem(index);
if(item!=null) {
Builder builder=new AlertDialog.Builder(context);
builder.setIcon(R.drawable.lojacidadaosmall);
builder.setTitle(item.getTitle());
builder.setMessage(item.getSnippet());
builder.setNegativeButton("OK", null);
builder.setPositiveButton("Go To", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent openMenu = new Intent("com.example.basicmaponline.INFOLOJA");
openMenu.putExtra("loja",listaLoja.get(index));
startActivity(openMenu);
}
});
builder.show();
}
return super.onTap(index);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
//getMenuInflater().inflate(R.menu.activity_main, menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.homeactionbar, menu);
return true;
}
//Botao para retroceder ( Action Bar)
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
if(item.getItemId()==R.id.lojasHome){
Intent intent = new Intent("com.example.basicmaponline.MENU");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
else {
super.onBackPressed();
}
return true;
}
public class loadDatabase extends AsyncTask<Void, Void, ArrayList<SQLloja>>{
@Override
protected ArrayList<SQLloja> doInBackground(Void... params) {
ArrayList<SQLloja> listaLojas = new ArrayList<SQLloja>();
try {
PostgreSQL pSQL = new PostgreSQL();
listaLojas = pSQL.getLojasCidadaoByOrder();
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return listaLojas;
}
@Override
protected void onPostExecute(ArrayList<SQLloja> listaLojas){
listaLoja = listaLojas;
}
}
/* Class My Location Listener */
public class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location loc){
double latitude = loc.getLatitude();
double longitude = loc.getLongitude();
Log.d("GPS","Latitude: "+latitude+" Longitude: "+longitude);
Log.d("GPS2",Integer.toString(mapView.getOverlays().size()));
GeoPoint point = new GeoPoint(latitude, longitude);
//gps.addItem(new OverlayItem(point, null, null));
//mapView.getOverlays().add(gps);
//mapView.getOverlays().get(2).requestRedraw();
//Marker marker = new Marker(R.drawable.mapsredpoiicon,point);
//mapView.getOverlays().get(3).r
OverlayItem item = new OverlayItem(point, null,null);
gpsItemizedOverlay.addItem(item);
mapView.getOverlays().add(itemizedOverlay);
}
@Override
public void onProviderDisabled(String provider){
}
@Override
public void onProviderEnabled(String provider){
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras){
}
} /*End of Class MyLocationListener*/
}
--
You received this message because you are subscribed to the Google Groups "mapsforge-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapsforge-de...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
mapView = new MapView(this, new MapnikTileDownloader());" It doesnt recognize now
Or OverlayItem doesnt recognize too.