1

in an application, i m using location based services of android

apart from that, i need to develop a feature wherein the user will be shown a map of the world (using google maps) . when clicked on a particular city or location, i want to launch a different activity by getting coordinate data of the clicked location
i have implemented maps b4 in a different context
the question is, how to go about this? any trigger would help please

Pratik Bhat
  • 7,166
  • 2
  • 35
  • 57

2 Answers2

0

If you are using MapView:

class MapOverlay extends Overlay
{
    @Override
    public boolean draw(Canvas canvas, MapView mapView, 
    boolean shadow, long when) 
    {
       //...
    }

    @Override
    public boolean onTouchEvent(MotionEvent event, MapView mapView) 
    {   

        if (event.getAction() == 1) {                
            GeoPoint p = mapView.getProjection().fromPixels(
                (int) event.getX(),
                (int) event.getY());
                // send the intent from here to your next activity with the GeoPoint coords.
                Toast.makeText(getBaseContext(), 
                    p.getLatitudeE6() / 1E6 + "," + 
                    p.getLongitudeE6() /1E6 , 
                    Toast.LENGTH_SHORT).show();
        }                            
        return false;
    }        
}
Reno
  • 33,594
  • 11
  • 89
  • 102
  • u mean i can set this as a background of my activity, and then launch an intent using those co-ordinates? – Pratik Bhat Oct 31 '11 at 06:41
  • Perhaps you need to [try out this tutorial to really understand this code](http://mobiforge.com/developing/story/using-google-maps-android) – Reno Oct 31 '11 at 06:44
  • this works, but it wil giv a toast even when u lift a finger after dragging, to solve that, i made an overlay class and override the onTap function in it – Pratik Bhat Nov 01 '11 at 04:51
0

I am not sure if I got your question right. But if your question is how to get the user's location correctly here is a similar question.

Community
  • 1
  • 1
Shadow
  • 6,161
  • 3
  • 20
  • 14