Map with Multiple bubbles On Long press add new Overlay
Main.java
---------
public class Main extends MapActivity {
ArrayList<String> name , latitude, longitude;
List<Overlay> mapOverlays;
MapView mapView;
Resources res;
GestureDetector mGestureDetector;
com.map.click.Main.MapOverlay mapOverlay;
List<Overlay> listOfOverlays;
GeoPoint stationpoint;
double a = 13.084656;
double b = 80.275007;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView)findViewById(R.id.mapview1);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(false);
mapOverlays = mapView.getOverlays();
res = this.getResources();
mGestureDetector = new GestureDetector(this, new LearnGestureListener());
listOfOverlays = mapView.getOverlays();
name = new ArrayList<String>();
latitude = new ArrayList<String>();
longitude = new ArrayList<String>();
name.add("Chennai Beach");
latitude.add("13.091566");
longitude.add("80.292211");
name.add("Medras HighCort");
latitude.add("13.08562");
longitude.add("80.285291");
name.add("Souther Railways(Chennai)");
latitude.add("13.084656");
longitude.add("80.275007");
name.add("OCS Bulding");
latitude.add("13.052393");
longitude.add("80.250479");
name.add("Gundi Railway station");
latitude.add("13.007797");
longitude.add("80.212512");
name.add("T.Nager");
latitude.add("13.039841");
longitude.add("80.231899");
stationpoint = new GeoPoint((int) (13.039841 * 1E6), (int) (80.231899 * 1E6));
MapOverlay mapOverlay = new MapOverlay(stationpoint);
listOfOverlays.add(mapOverlay);
for(int i= 0; i< name.size(); i++){
mapView.setStreetView(false);
stationpoint = new GeoPoint((int) (Double.parseDouble(latitude.get(i)) * 1E6),
(int) (Double.parseDouble(longitude.get(i)) * 1E6));
OverlayItem overlayitem1 = new OverlayItem(stationpoint, "","");
Drawable drawable = this.getResources().getDrawable(R.drawable.pink);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, mapView );
itemizedoverlay.addOverlay(overlayitem1);
mapOverlays.add(itemizedoverlay);
}
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
@Override
public boolean onTouchEvent(MotionEvent e) {
mGestureDetector.onTouchEvent(e);
return super.onTouchEvent(e);
}
class MapOverlay extends com.google.android.maps.Overlay{
GeoPoint point;
public MapOverlay(GeoPoint p ) {
point = p;
}
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
super.draw(canvas, mapView, shadow);
Bitmap bmp;
//---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(point, screenPts);
//---add the marker---
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.epingle_grande_actualite);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y, null);
return true;
}
@Override
public boolean onTouchEvent(MotionEvent e, MapView mapView) {
mGestureDetector.onTouchEvent(e);
return super.onTouchEvent(e, mapView);
}
}
class LearnGestureListener extends GestureDetector.SimpleOnGestureListener{
@Override
public boolean onSingleTapUp(MotionEvent ev) {
Log.d("onSingleTapUp",ev.toString());
return true;
}
@Override
public boolean onDoubleTap(MotionEvent ev) {
Log.d("onSingleTapUp",ev.toString());
mapView.getController().zoomIn();
return true;
}
@Override
public void onShowPress(MotionEvent ev) {
Log.d("onShowPress",ev.toString());
}
@Override
public void onLongPress(MotionEvent e) {
GeoPoint point = mapView.getProjection().fromPixels((int) e.getX(),(int) e.getY());
double k =0.0;
//listOfOverlays.removeAll(listOfOverlays);
mapOverlays.removeAll(mapOverlays);
//stationpoint = new GeoPoint((int) (13.039841 * 1E6), (int) (80.231899 * 1E6));
MapOverlay mapOverlay = new MapOverlay(point);
listOfOverlays.add(mapOverlay);
for(int i= 0; i< 5; i++){
GeoPoint stationpoint1 = new GeoPoint((int) ((a + k) * 1E6), (int) ((b + k) * 1E6));
OverlayItem overlayitem1 = new OverlayItem(stationpoint1,"","");
Drawable drawable = res.getDrawable(R.drawable.pink);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, mapView );
itemizedoverlay.addOverlay(overlayitem1);
mapOverlays.add(itemizedoverlay);
k = k + 0.12;
}
a = a - 0.5;
b = b - 0.5;
System.out.println("hiiii am tested " + a +"," + b);
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
Log.d("onScroll",e1.toString());
return true;
}
@Override
public boolean onDown(MotionEvent ev) {
Log.d("onDownd",ev.toString());
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
Log.d("d",e1.toString());
Log.d("e2",e2.toString());
return true;
}
}
}
HelloItemizedOverlay.java
---------------------------
public class HelloItemizedOverlay extends ItemizedOverlay {
MapView mapView;
Context mContext;
GeoPoint destnationPoint, sourcePoint;
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
public HelloItemizedOverlay(Drawable defaultMarker,MapView map ) {
super(boundCenterBottom(defaultMarker));
mapView = map;
this.mContext = map.getContext();
}
public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
super(defaultMarker);
mContext = context;
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
@Override
protected boolean onTap(int index) {
return true;
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
@Override
public void draw(android.graphics.Canvas canvas,MapView mapView, boolean shadow)
{
super.draw(canvas, mapView, false);
}
}
main.xml:
---------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.android.maps.MapView
android:id="@+id/mapview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="04khj0ICP9WQ_EfJr_i1Kx_0J7ufBy_nimdLgfQ"/>
</LinearLayout>
Main.java
---------
public class Main extends MapActivity {
ArrayList<String> name , latitude, longitude;
List<Overlay> mapOverlays;
MapView mapView;
Resources res;
GestureDetector mGestureDetector;
com.map.click.Main.MapOverlay mapOverlay;
List<Overlay> listOfOverlays;
GeoPoint stationpoint;
double a = 13.084656;
double b = 80.275007;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView)findViewById(R.id.mapview1);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(false);
mapOverlays = mapView.getOverlays();
res = this.getResources();
mGestureDetector = new GestureDetector(this, new LearnGestureListener());
listOfOverlays = mapView.getOverlays();
name = new ArrayList<String>();
latitude = new ArrayList<String>();
longitude = new ArrayList<String>();
name.add("Chennai Beach");
latitude.add("13.091566");
longitude.add("80.292211");
name.add("Medras HighCort");
latitude.add("13.08562");
longitude.add("80.285291");
name.add("Souther Railways(Chennai)");
latitude.add("13.084656");
longitude.add("80.275007");
name.add("OCS Bulding");
latitude.add("13.052393");
longitude.add("80.250479");
name.add("Gundi Railway station");
latitude.add("13.007797");
longitude.add("80.212512");
name.add("T.Nager");
latitude.add("13.039841");
longitude.add("80.231899");
stationpoint = new GeoPoint((int) (13.039841 * 1E6), (int) (80.231899 * 1E6));
MapOverlay mapOverlay = new MapOverlay(stationpoint);
listOfOverlays.add(mapOverlay);
for(int i= 0; i< name.size(); i++){
mapView.setStreetView(false);
stationpoint = new GeoPoint((int) (Double.parseDouble(latitude.get(i)) * 1E6),
(int) (Double.parseDouble(longitude.get(i)) * 1E6));
OverlayItem overlayitem1 = new OverlayItem(stationpoint, "","");
Drawable drawable = this.getResources().getDrawable(R.drawable.pink);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, mapView );
itemizedoverlay.addOverlay(overlayitem1);
mapOverlays.add(itemizedoverlay);
}
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
@Override
public boolean onTouchEvent(MotionEvent e) {
mGestureDetector.onTouchEvent(e);
return super.onTouchEvent(e);
}
class MapOverlay extends com.google.android.maps.Overlay{
GeoPoint point;
public MapOverlay(GeoPoint p ) {
point = p;
}
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
super.draw(canvas, mapView, shadow);
Bitmap bmp;
//---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(point, screenPts);
//---add the marker---
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.epingle_grande_actualite);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y, null);
return true;
}
@Override
public boolean onTouchEvent(MotionEvent e, MapView mapView) {
mGestureDetector.onTouchEvent(e);
return super.onTouchEvent(e, mapView);
}
}
class LearnGestureListener extends GestureDetector.SimpleOnGestureListener{
@Override
public boolean onSingleTapUp(MotionEvent ev) {
Log.d("onSingleTapUp",ev.toString());
return true;
}
@Override
public boolean onDoubleTap(MotionEvent ev) {
Log.d("onSingleTapUp",ev.toString());
mapView.getController().zoomIn();
return true;
}
@Override
public void onShowPress(MotionEvent ev) {
Log.d("onShowPress",ev.toString());
}
@Override
public void onLongPress(MotionEvent e) {
GeoPoint point = mapView.getProjection().fromPixels((int) e.getX(),(int) e.getY());
double k =0.0;
//listOfOverlays.removeAll(listOfOverlays);
mapOverlays.removeAll(mapOverlays);
//stationpoint = new GeoPoint((int) (13.039841 * 1E6), (int) (80.231899 * 1E6));
MapOverlay mapOverlay = new MapOverlay(point);
listOfOverlays.add(mapOverlay);
for(int i= 0; i< 5; i++){
GeoPoint stationpoint1 = new GeoPoint((int) ((a + k) * 1E6), (int) ((b + k) * 1E6));
OverlayItem overlayitem1 = new OverlayItem(stationpoint1,"","");
Drawable drawable = res.getDrawable(R.drawable.pink);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, mapView );
itemizedoverlay.addOverlay(overlayitem1);
mapOverlays.add(itemizedoverlay);
k = k + 0.12;
}
a = a - 0.5;
b = b - 0.5;
System.out.println("hiiii am tested " + a +"," + b);
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
Log.d("onScroll",e1.toString());
return true;
}
@Override
public boolean onDown(MotionEvent ev) {
Log.d("onDownd",ev.toString());
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
Log.d("d",e1.toString());
Log.d("e2",e2.toString());
return true;
}
}
}
HelloItemizedOverlay.java
---------------------------
public class HelloItemizedOverlay extends ItemizedOverlay {
MapView mapView;
Context mContext;
GeoPoint destnationPoint, sourcePoint;
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
public HelloItemizedOverlay(Drawable defaultMarker,MapView map ) {
super(boundCenterBottom(defaultMarker));
mapView = map;
this.mContext = map.getContext();
}
public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
super(defaultMarker);
mContext = context;
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
@Override
protected boolean onTap(int index) {
return true;
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
@Override
public void draw(android.graphics.Canvas canvas,MapView mapView, boolean shadow)
{
super.draw(canvas, mapView, false);
}
}
main.xml:
---------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.android.maps.MapView
android:id="@+id/mapview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="04khj0ICP9WQ_EfJr_i1Kx_0J7ufBy_nimdLgfQ"/>
</LinearLayout>
1 comment:
Hello. And Bye.
-----------------------
i'm isglasses.com
Post a Comment