How to create a clickable overlay

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

How to create a clickable overlay

Postby iSon » Mon Jun 29, 2009 3:21 pm

Hi All,
I wonder if it is possible to make a Map Overlay clickable. I want to click on the Overlay image on the map to display some information for this image (such as name, address, phone num, ...)

Any help would be greatly appreciated
iSon
Freshman
Freshman
 
Posts: 5
Joined: Mon Jun 29, 2009 3:18 pm

Top

Postby Christoph » Thu Jul 02, 2009 11:07 am

This tutorial helped me a lot:
http://mobiforge.com/developing/story/u ... ps-android

chapter "Getting the Location that was touched" is the key for your request
User avatar
Christoph
Developer
Developer
 
Posts: 28
Joined: Thu Jul 02, 2009 3:34 am
Location: Bonn, Germany

Postby iSon » Thu Jul 02, 2009 2:04 pm

I have read this tutorial before, but the chapter that u mentioned is for all points in map, but all i need is only for marker. Btw thx for ur reply
iSon
Freshman
Freshman
 
Posts: 5
Joined: Mon Jun 29, 2009 3:18 pm

Postby Christoph » Thu Jul 02, 2009 9:37 pm

oh sorry, was in a hurry and just read "click overlay" :D

its a problem i'll have to face the next day too. if you find a solution before me, please let me know :)
User avatar
Christoph
Developer
Developer
 
Posts: 28
Joined: Thu Jul 02, 2009 3:34 am
Location: Bonn, Germany

Postby arvind » Fri Jul 03, 2009 11:20 am

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.  
  2. package com.android.poc;
  3.  
  4.  
  5.  
  6. import java.util.ArrayList;
  7.  
  8.  
  9.  
  10. import android.graphics.drawable.Drawable;
  11.  
  12.  
  13.  
  14. import com.google.android.maps.ItemizedOverlay;
  15.  
  16. import com.google.android.maps.OverlayItem;
  17.  
  18.  
  19.  
  20. public class HelloItemizedOverlay extends ItemizedOverlay<OverlayItem> {
  21.  
  22.        
  23.  
  24.         private ArrayList<OverlayItem> mOverlays= new ArrayList<OverlayItem>();;
  25.  
  26.         public HelloItemizedOverlay(Drawable defaultMarker) {
  27.  
  28.                 super(defaultMarker);
  29.  
  30.                
  31.  
  32.                 // TODO Auto-generated constructor stub
  33.  
  34.         }
  35.  
  36.         public void addOverlay(OverlayItem overlay) {
  37.  
  38.             mOverlays.add(overlay);
  39.  
  40.             System.out.println("success");
  41.  
  42.             populate();
  43.  
  44.         }
  45.  
  46.         @Override
  47.  
  48.         protected OverlayItem createItem(int i) {
  49.  
  50.                 // TODO Auto-generated method stub
  51.  
  52.                 System.out.println("Created"+i);
  53.  
  54.                 return mOverlays.get(i);
  55.  
  56.         }
  57.  
  58.  
  59.  
  60.         @Override
  61.  
  62.         public int size() {
  63.  
  64.                 // TODO Auto-generated method stub
  65.  
  66.                 //System.out.println("Size:"+mOverlays.size());
  67.  
  68.                 return mOverlays.size();
  69.  
  70.         }
  71.  
  72.         @Override
  73.  
  74.         protected boolean onTap(int index) {
  75.  
  76.                 // TODO Auto-generated method stub
  77.  
  78.                
  79.  
  80.                 //Here add code for click event
  81.  
  82.                
  83.  
  84.                
  85.  
  86.                 return super.onTap(index);
  87.  
  88.         }
  89.  
  90.        
  91.  
  92.        
  93.  
  94.        
  95.  
  96.  
  97.  
  98. }
  99.  
  100.  
  101.  
  102.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4



Here the MapsActivity ka class

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package com.android.poc;
  3.  
  4.  
  5.  
  6. import java.util.List;
  7.  
  8. import android.graphics.drawable.Drawable;
  9.  
  10. import android.os.Bundle;
  11.  
  12. import com.google.android.maps.GeoPoint;
  13.  
  14. import com.google.android.maps.MapActivity;
  15.  
  16. import com.google.android.maps.MapController;
  17.  
  18. import com.google.android.maps.MapView;
  19.  
  20. import com.google.android.maps.Overlay;
  21.  
  22. import com.google.android.maps.OverlayItem;
  23.  
  24.  
  25.  
  26.  
  27.  
  28. public class HelloMapView extends MapActivity {
  29.  
  30.     /** Called when the activity is first created. */
  31.  
  32.         List<Overlay> mapOverlays;
  33.  
  34.         Drawable drawable;
  35.  
  36.         HelloItemizedOverlay itemizedoverlay;
  37.  
  38.         MapView mapView;
  39.  
  40.         MapController mc;
  41.  
  42.     @Override
  43.  
  44.     public void onCreate(Bundle savedInstanceState) {
  45.  
  46.         super.onCreate(savedInstanceState);
  47.  
  48.         setContentView(R.layout.main);
  49.  
  50.         mapView = (MapView) findViewById(R.id.mapview);
  51.  
  52.         mc=mapView.getController();
  53.  
  54.         mapOverlays = mapView.getOverlays();//done
  55.  
  56.         mapView.setBuiltInZoomControls(true);
  57.  
  58.         drawable = this.getResources().getDrawable(R.drawable.androidmarker);
  59.  
  60.         itemizedoverlay = new HelloItemizedOverlay(drawable);
  61.  
  62.         GeoPoint point = new GeoPoint(19122572,72914864);
  63.  
  64.        
  65.  
  66.         OverlayItem overlayitem = new OverlayItem(point, "Hi", "Hello");
  67.  
  68.         itemizedoverlay.addOverlay(overlayitem);
  69.  
  70.         mapOverlays.add(itemizedoverlay);
  71.  
  72.            
  73.  
  74.                
  75.  
  76.      
  77.  
  78.                 mapView.postInvalidate();
  79.  
  80.                 mc.animateTo(point);
  81.  
  82.        
  83.  
  84.     }
  85.  
  86.    
  87.  
  88.    
  89.  
  90.    
  91.  
  92.    
  93.  
  94.     protected boolean isRouteDisplayed()
  95.  
  96.     {
  97.  
  98.         return false;
  99.  
  100.     }
  101.  
  102. }
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4

This is Manifest.xml

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.  
  3.  
  4. <?xml version="1.0" encoding="utf-8"?>
  5.  
  6. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  7.  
  8.      package="com.android.poc"
  9.  
  10.      android:versionCode="1"
  11.  
  12.      android:versionName="1.0">
  13.  
  14.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  15.  
  16.         <uses-library android:name="com.google.android.maps" />
  17.  
  18.         <activity android:name=".HelloMapView"
  19.  
  20.                  android:label="@string/app_name">
  21.  
  22.             <intent-filter>
  23.  
  24.                 <action android:name="android.intent.action.MAIN" />
  25.  
  26.                 <category android:name="android.intent.category.LAUNCHER" />
  27.  
  28.             </intent-filter>
  29.  
  30.         </activity>
  31.  
  32.     </application>
  33.  
  34.     <uses-permission android:name="android.permission.INTERNET" />
  35.  
  36.     <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" />
  37.  
  38.  
  39.  
  40.  
  41.  
  42. </manifest>
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
Parsed in 0.004 seconds, using GeSHi 1.0.8.4



This is main.xml file ....
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.    android:id="@+id/mainlayout"
  7.  
  8.    android:orientation="vertical"
  9.  
  10.    android:layout_width="fill_parent"
  11.  
  12.    android:layout_height="fill_parent" >
  13.  
  14.  
  15.  
  16.     <com.google.android.maps.MapView
  17.  
  18.        android:id="@+id/mapview"
  19.  
  20.        android:layout_width="fill_parent"
  21.  
  22.        android:layout_height="fill_parent"
  23.  
  24.        android:enabled="true"
  25.  
  26.        android:clickable="true"
  27.  
  28.        android:apiKey=write key here
  29.  
  30.    />
  31.  
  32. <LinearLayout
  33.  
  34.    android:id="@+id/zoomview"
  35.  
  36.    android:layout_width="wrap_content"
  37.  
  38.    android:layout_height="wrap_content"
  39.  
  40.    android:layout_alignBottom="@id/mapview"
  41.  
  42.    android:layout_centerHorizontal="true"
  43.  
  44. />
  45.  
  46. </RelativeLayout>
  47.  
  48.  
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
arvind
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jun 23, 2009 4:44 am
Location: Mumbai,India

Postby Christoph » Sat Jul 04, 2009 9:46 am

Hi Folks,

i found a tutorial that addresses to our needs:

http://blog.pocketjourney.com/2008/03/1 ... p-windows/

good look :-)
User avatar
Christoph
Developer
Developer
 
Posts: 28
Joined: Thu Jul 02, 2009 3:34 am
Location: Bonn, Germany

Top

Postby arvind » Sun Jul 05, 2009 9:27 pm

Cristoph sir ... thanks for prompt reply....
did u try the code i have posted... did it work ?
your link is nice
however android 1.5 is latest and there is no MapLocation class in that....
iSon sir has got the solution .. he has post in other topic..
iSon sir can u post the code.... it will helpful for me sir...
My english also becomes better... but i am stuck in same problem...

Thanks...
arvind
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jun 23, 2009 4:44 am
Location: Mumbai,India

Postby Christoph » Mon Jul 06, 2009 1:22 am

arvind wrote:however android 1.5 is latest and there is no MapLocation class in that....


Hi Arvind,

it is intended that you create it by youself:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class MapLocation {
  3.  
  4.  
  5.  
  6.         private GeoPoint        point;
  7.  
  8.         private String          name;
  9.  
  10.  
  11.  
  12.         public MapLocation(String name,double latitude, double longitude) {
  13.  
  14.                 this.name = name;
  15.  
  16.                 point = new GeoPoint((int)(latitude*1e6),(int)(longitude*1e6));
  17.  
  18.         }
  19.  
  20.  
  21.  
  22.         public GeoPoint getPoint() {
  23.  
  24.                 return point;
  25.  
  26.         }
  27.  
  28.  
  29.  
  30.         public String getName() {
  31.  
  32.                 return name;
  33.  
  34.         }
  35.  
  36. }
  37.  
  38.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
User avatar
Christoph
Developer
Developer
 
Posts: 28
Joined: Thu Jul 02, 2009 3:34 am
Location: Bonn, Germany

Postby arvind » Mon Jul 06, 2009 8:09 am

Christoph Sir Tausend Dank!
You have be very kind to share your knowledge...
This really help...
Thank you for quick replying....

regards
Arvind
arvind
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jun 23, 2009 4:44 am
Location: Mumbai,India

Postby Christoph » Mon Jul 06, 2009 11:42 am

you are welcome !

by the way, this is working for me:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.  
  3.      protected boolean onTap(int index) {
  4.  
  5.           // TODO Auto-generated method stub
  6.  
  7.          
  8.  
  9.           //Here add code for click event
  10.  
  11.          
  12.  
  13.          
  14.  
  15.           return super.onTap(index);
  16.  
  17.      }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


a much easier approach. but it has a realy tolerant detection.
even clicks nearby are registered.
for me, its ok.
User avatar
Christoph
Developer
Developer
 
Posts: 28
Joined: Thu Jul 02, 2009 3:34 am
Location: Bonn, Germany

Postby arvind » Mon Jul 06, 2009 7:50 pm

Cristoph sir ..
I have be trying that ItemizedOverlay example for abt 2 weeks now...
it suit my requirement.. but i have not be able to make that work...
the overlay does not appear ...
could u please put up simple working code of that... it will be very kind of u

thanks and regards once again
Arvind
arvind
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jun 23, 2009 4:44 am
Location: Mumbai,India

Postby arvind » Tue Jul 07, 2009 7:05 am

I have been able to make it work sir..
Dont take the trouble...

Actually i want to draw path only when on tap event of overlay item occurs (using ItemizedOverlay.....)
I have working code of path drawing... from google driving direction tutoral
Now should i use both overlays... or only one
Thanks for guidance....

Regards
Arvind
arvind
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jun 23, 2009 4:44 am
Location: Mumbai,India

Postby alexbrown » Tue Jul 21, 2009 11:14 am

hi all!
is it possible change the cursor's aspect when it is on an item drawed?

for example, i want that appear an hand when the cursor is on a line

sorry for my english :oops: i'm italian
alexbrown
Freshman
Freshman
 
Posts: 9
Joined: Thu Jul 16, 2009 5:10 pm

Postby Christoph » Tue Jul 21, 2009 1:54 pm

alexbrown wrote:hi all!
is it possible change the cursor's aspect when it is on an item drawed?

for example, i want that appear an hand when the cursor is on a line

sorry for my english :oops: i'm italian


on a real device you won't have a cursor :D

you can change the marker depending on its state:

OverlayItem.ITEM_STATE_FOCUSED_MASK = 4;
OverlayItem.ITEM_STATE_SELECTED_MASK = 2;
OverlayItem.ITEM_STATE_PRESSED_MASK = 1;

Override public Drawable getMarker(int i)

Note: if you tap an item its state will be ITEM_STATE_FOCUSED_MASK + ITEM_STATE_SELECTED_MASK (=6)
User avatar
Christoph
Developer
Developer
 
Posts: 28
Joined: Thu Jul 02, 2009 3:34 am
Location: Bonn, Germany

Postby alexbrown » Wed Jul 22, 2009 9:12 am

Christoph wrote:on a real device you won't have a cursor :D


ah, it's true,

thank you very much
alexbrown
Freshman
Freshman
 
Posts: 9
Joined: Thu Jul 16, 2009 5:10 pm

Top
Next

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 5 guests