Change pushpin in overlay corresponding to touch

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

Change pushpin in overlay corresponding to touch

Postby thetuxracer » Sun Feb 07, 2010 10:14 am

Hi,
I took a look at overlays, but i am facing a problem:
The pin/droid is drawn at the location that is hardcoded. WHat i wish to do. is draw the pin/droid on screen, which was last touched. The SDK doesnt give any examples regarding that. Can you help me?

Thanks!

EDIT
I was able to come up with an idea. from this code I got (from mobiForge). It updates the lat and long in a Toast.

MODIFIED PROBLEM:
ANd I want to draw a pushpin, where I just clicked. What function sould I use for that?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public boolean onTouchEvent(MotionEvent event, MapView mapView){
  2.  
  3.                 //---when user lifts his finger---
  4.  
  5.             if (event.getAction() == 1) {                
  6.  
  7.                 GeoPoint p = mapView.getProjection().fromPixels(
  8.  
  9.                     (int) event.getX(),
  10.  
  11.                     (int) event.getY());
  12.  
  13.                     Toast.makeText(getBaseContext(),
  14.  
  15.                         p.getLatitudeE6() / 1E6 + "," +
  16.  
  17.                         p.getLongitudeE6() /1E6 ,
  18.  
  19.                         Toast.LENGTH_SHORT).show();
  20.  
  21.             }                            
  22.  
  23.             return false;
  24.  
  25.         }        
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Thanks :)
thetuxracer
Developer
Developer
 
Posts: 26
Joined: Mon Jan 04, 2010 7:59 am
Location: Nashik, MH, India

Top

Postby nicholas.hauschild » Mon Feb 08, 2010 2:17 pm

Hello thetuxracer,

It sounds to me like you may be using an object which extends the ItemizedOverlay<T>. If this is the case, you are probably holding a collection of your parameterized type (or perhaps a reference to just a single T).

Anyways, on your onTouchEvent, you probably want to do something like this:

if using a collection
-- clear your collection
-- call setLastFocusedIndex(-1) in the ItemizedOverlay class
-- add the NEW pin overlay to your collection, providing the new coordinates

if using a single reference
-- call setLastFocusedIndex(-1) in the ItemizedOverlay class
-- to your reference, assign the NEW pin overlay.

Hope this is helpful, please let me know if this works out for you.

Good Luck!
-Nick
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Postby thetuxracer » Fri Feb 12, 2010 3:12 am

wow, that was totally new, but will read-up on it. i also had thought of something like that, to the effect that i will create an overlay dynamically, and use add(Overlay).

thanks for the reply, danke schoen.
thetuxracer
Developer
Developer
 
Posts: 26
Joined: Mon Jan 04, 2010 7:59 am
Location: Nashik, MH, India

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 4 guests