public class Tab1 extends FragmentActivity {
private LocationManager locManager;
private LatLng markerLatLng;
private LatLng markerLatLngP;
public GeoPoint[] point;
public OverlayItem[] overlayitem;
public List<Grafiti> grafiti_Lst = Activity_Principal.getGeoPointLst();
private GoogleMap googleMap;
private Marker marker;
private Hashtable
<String, String
> markers
; private ImageLoader imageLoader;
private DisplayImageOptions options;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab1);
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
initImageLoader();
markers
= new Hashtable
<String, String
>(); imageLoader = ImageLoader.getInstance();
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.img_carga2) // Display Stub Image
.showImageForEmptyUri(R.drawable.img_error) // If Empty image found
.cacheInMemory()
.cacheOnDisc().bitmapConfig(Bitmap.Config.RGB_565).build();
//SACO LAS COORDENADAS ACTUALES
locManager
= (LocationManager
)getSystemService
(Context.
LOCATION_SERVICE); Location loc = locManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if(loc != null)
{
latitud
= Double.
valueOf(loc.
getLatitude()); longitud
= Double.
valueOf(loc.
getLongitude()); }
markerLatLng = new LatLng(latitud, longitud);
if ( googleMap != null ) {
generateMap();
googleMap.setInfoWindowAdapter(new CustomInfoWindowAdapter());
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(markerLatLng, 14));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(12), 2000, null);
}
}
private class CustomInfoWindowAdapter implements InfoWindowAdapter {
public CustomInfoWindowAdapter() {
view = getLayoutInflater().inflate(R.layout.balloon, null);
}
@Override
public View getInfoContents
(Marker marker
) {
if (Tab1.this.marker != null && Tab1.this.marker.isInfoWindowShown()) {
Tab1.this.marker.hideInfoWindow();
Tab1.this.marker.showInfoWindow();
}
return null;
}
@Override
public View getInfoWindow
(final Marker marker
) { Tab1.this.marker = marker;
if (marker.getId() != null && markers != null && markers.size() > 0) {
if ( markers.get(marker.getId()) != null &&
markers.get(marker.getId()) != null) {
url = markers.get(marker.getId());
}
}
final ImageView image = ((ImageView) view.findViewById(R.id.imgP));
if (url != null && !url.equalsIgnoreCase("null")
&& !url.equalsIgnoreCase("")) {
imageLoader.displayImage(url, image, options,
new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete
(String imageUri,
View view, Bitmap loadedImage
) { super.onLoadingComplete(imageUri, view, loadedImage);
getInfoContents(marker);
}
});
} else {
image.setImageResource(R.drawable.map_error);
imagen_error = 1;
}
return view;
}
}
private void initImageLoader() {
int memoryCacheSize;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
int memClass = ((ActivityManager)
getSystemService
(Context.
ACTIVITY_SERVICE)) .getMemoryClass();
memoryCacheSize = (memClass / 8) * 1024 * 1024;
} else {
memoryCacheSize = 2 * 1024 * 1024;
}
final ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
this).threadPoolSize(5)
.
threadPriority(Thread.
NORM_PRIORITY - 2) .memoryCacheSize(memoryCacheSize)
.memoryCache(new FIFOLimitedMemoryCache(memoryCacheSize-1000000))
.denyCacheImageMultipleSizesInMemory()
.discCacheFileNameGenerator(new Md5FileNameGenerator())
.tasksProcessingOrder(QueueProcessingType.LIFO).enableLogging()
.build();
ImageLoader.getInstance().init(config);
}
private void generateMap() {
LatLng markerLatLngP1 = new LatLng(latitud, longitud);
//Posición actual
googleMap.addMarker(new MarkerOptions()
.position(markerLatLngP1)
.anchor(0.5f, 1)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.places_current)));
//Recorro el vector de latitud y longitud y voy agregando los puntos al mapa.
for (int i = 0; i < g_Lst.size(); i++)
{
markerLatLngP = new LatLng((g_Lst.get(i).getLatitud()),(g_Lst.get(i).getLongitud()));
final Marker kiel = googleMap.addMarker(new MarkerOptions()
.position(markerLatLngP)
.title(g_Lst.get(i).getNombre())
.snippet(g_Lst.get(i).getImagen())
.anchor(0.5f, 1)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.places)));
markers.put(kiel.getId(), g_Lst.get(i).getImagen());
markerLatLngP = null;
googleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
if (imagen_error == 1){
imagen_error = 0;
return;
}
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(sharingIntent, "Texto"));
}
});
}
}
}