How to create a clickable overlay

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Postby zpk1234 » Thu Aug 20, 2009 1:35 pm

arvind wrote:Hi Christoph and iSon
i thinks i found the solution but not able make work...

For Click events on marker you must use ItemizedOverlay class
check this
http://developer.android.com/guide/tuto ... pview.html

I putting the code... but not working... can anyone please try and tell me error

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.android.poc;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import android.graphics.drawable.Drawable;
  6.  
  7. import com.google.android.maps.ItemizedOverlay;
  8. import com.google.android.maps.OverlayItem;
  9.  
  10. public class HelloItemizedOverlay extends ItemizedOverlay<OverlayItem> {
  11.        
  12.         private ArrayList<OverlayItem> mOverlays= new ArrayList<OverlayItem>();;
  13.         public HelloItemizedOverlay(Drawable defaultMarker) {
  14.                 super(defaultMarker);
  15.                
  16.                 // TODO Auto-generated constructor stub
  17.         }
  18.         public void addOverlay(OverlayItem overlay) {
  19.             mOverlays.add(overlay);
  20.             System.out.println("success");
  21.             populate();
  22.         }
  23.         @Override
  24.         protected OverlayItem createItem(int i) {
  25.                 // TODO Auto-generated method stub
  26.                 System.out.println("Created"+i);
  27.                 return mOverlays.get(i);
  28.         }
  29.  
  30.         @Override
  31.         public int size() {
  32.                 // TODO Auto-generated method stub
  33.                 //System.out.println("Size:"+mOverlays.size());
  34.                 return mOverlays.size();
  35.         }
  36.         @Override
  37.         protected boolean onTap(int index) {
  38.                 // TODO Auto-generated method stub
  39.                
  40.                 //Here add code for click event
  41.                
  42.                
  43.                 return super.onTap(index);
  44.         }
  45.        
  46.        
  47.        
  48.  
  49. }
  50.  
  51.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4



Here the MapsActivity ka class

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.android.poc;
  2.  
  3. import java.util.List;
  4. import android.graphics.drawable.Drawable;
  5. import android.os.Bundle;
  6. import com.google.android.maps.GeoPoint;
  7. import com.google.android.maps.MapActivity;
  8. import com.google.android.maps.MapController;
  9. import com.google.android.maps.MapView;
  10. import com.google.android.maps.Overlay;
  11. import com.google.android.maps.OverlayItem;
  12.  
  13.  
  14. public class HelloMapView extends MapActivity {
  15.     /** Called when the activity is first created. */
  16.         List<Overlay> mapOverlays;
  17.         Drawable drawable;
  18.         HelloItemizedOverlay itemizedoverlay;
  19.         MapView mapView;
  20.         MapController mc;
  21.     @Override
  22.     public void onCreate(Bundle savedInstanceState) {
  23.         super.onCreate(savedInstanceState);
  24.         setContentView(R.layout.main);
  25.         mapView = (MapView) findViewById(R.id.mapview);
  26.         mc=mapView.getController();
  27.         mapOverlays = mapView.getOverlays();//done
  28.         mapView.setBuiltInZoomControls(true);
  29.         drawable = this.getResources().getDrawable(R.drawable.androidmarker);
  30.         itemizedoverlay = new HelloItemizedOverlay(drawable);
  31.         GeoPoint point = new GeoPoint(19122572,72914864);
  32.        
  33.         OverlayItem overlayitem = new OverlayItem(point, "Hi", "Hello");
  34.         itemizedoverlay.addOverlay(overlayitem);
  35.         mapOverlays.add(itemizedoverlay);
  36.            
  37.                
  38.      
  39.                 mapView.postInvalidate();
  40.                 mc.animateTo(point);
  41.        
  42.     }
  43.    
  44.    
  45.    
  46.    
  47.     protected boolean isRouteDisplayed()
  48.     {
  49.         return false;
  50.     }
  51. }
  52.  
  53.  
  54.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4

This is Manifest.xml

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  4.      package="com.android.poc"
  5.      android:versionCode="1"
  6.      android:versionName="1.0">
  7.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  8.         <uses-library android:name="com.google.android.maps" />
  9.         <activity android:name=".HelloMapView"
  10.                  android:label="@string/app_name">
  11.             <intent-filter>
  12.                 <action android:name="android.intent.action.MAIN" />
  13.                 <category android:name="android.intent.category.LAUNCHER" />
  14.             </intent-filter>
  15.         </activity>
  16.     </application>
  17.     <uses-permission android:name="android.permission.INTERNET" />
  18.     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission><uses-sdk android:minSdkVersion="3" />
  19.  
  20.  
  21. </manifest>
  22.  
  23.  
  24.  
Parsed in 0.004 seconds, using GeSHi 1.0.8.4



This is main.xml file ....
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:id="@+id/mainlayout"
  4.    android:orientation="vertical"
  5.    android:layout_width="fill_parent"
  6.    android:layout_height="fill_parent" >
  7.  
  8.     <com.google.android.maps.MapView
  9.        android:id="@+id/mapview"
  10.        android:layout_width="fill_parent"
  11.        android:layout_height="fill_parent"
  12.        android:enabled="true"
  13.        android:clickable="true"
  14.        android:apiKey=write key here
  15.    />
  16. <LinearLayout
  17.    android:id="@+id/zoomview"
  18.    android:layout_width="wrap_content"
  19.    android:layout_height="wrap_content"
  20.    android:layout_alignBottom="@id/mapview"
  21.    android:layout_centerHorizontal="true"
  22. />
  23. </RelativeLayout>
  24.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4



once more, forgive my english it is poor , i am learn english slow than android :) . .... i try best ... school teacher not teach nice...


please help out me

Regards
arvind


change these code

public HelloItemizedOverlay(Drawable defaultMarker) {
super(defaultMarker);

// TODO Auto-generated constructor stub
}

to

public HelloItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));

// TODO Auto-generated constructor stub
}
zpk1234
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Jun 27, 2009 1:17 pm

Top

Postby kevindorson » Wed May 05, 2010 5:43 pm

HI arvind,
could u please post the same code for the onTap click on the markers of the map. even i've been working on a similar problem and i've been stuck in the same place.
i wanted someting like onTap on a particular marker pops up a transparent popup with some text details and ten upon click of the same takes me to a new activity alltogether
let me know if u ned more info
kevindorson
Developer
Developer
 
Posts: 44
Joined: Mon Mar 29, 2010 11:51 am

Re: How to create a clickable overlay

Postby pedroteixeira07 » Mon Jul 05, 2010 10:15 pm

Hello,

I'm dealling with the same issue.. make a map Overlay clickable.. possibly a pop up window with information, or even more clickable options.. any solutions for this? Any code snippet would be appreciatted..

By now I have my overlays already in the map, working fine. The thing is .. I won't the information of each one to be different when they are touched.. so I'm not sure how to do it..

Thank you in advance
pedroteixeira07
Experienced Developer
Experienced Developer
 
Posts: 74
Joined: Sun Oct 18, 2009 6:06 pm
Location: Funchal

Top
Previous

Return to Map Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests