tags:

views:

166

answers:

2

Hi Friends,

I am new to Android GPS application development.I have to show multiple location in the map and if user touches any one of the location then it should display the information about that place.Now my problem is i could not able to get the exact location in the touch event.Is there any way to get the exact pointed location of image in the overlay.

A: 

The method onTouchEvent is as follow:

public boolean onTouchEvent(MotionEvent event, MapView mapView)

You can retrieve the location of the point with the following:

Projection projection = mapView.getProjection();
GeoPoint g = projection.fromPixels((int)event.getX(),(int)event.getY());

Edit:

This is just an idea. Maybe you can have a look at the doc for ItemizedOverlay, and more particularly onTap(int index)

I guess you will have to keep track of your overlays in an array and with the index, retrieve the corresponding overlay item

ccheneson
Hi ccheneson,Thanks for immediate response i already tried this, using this one we can able to get the longitude and latitude of the place where we are touching but what i want is, i need to get the exact longitude and latitude of value selected place. for-ex) consider two images A and B pointing two places correspondingly place1 and place2 in map.when user touch the image A it should display the exact longitude and latitude of place1 like wise when user touch image B it should display the points of place2.How to achieve this?
Kumar
A: 

Something like this might be helpful to you?

If you want to get lat and long you can use the GeoPoint tapPoint to get them.

private mapLocation getHitMapLocation(MapView mapView, GeoPoint tapPoint) 
{ 
    mapLocation hitMapLocation = null; 
    RectF hitTestRecr = new RectF(); 
    Point screenCoords = new Point(); 
    Iterator iterator = mapLocationViewer.getMapLocations().iterator(); 
    while(iterator.hasNext()) {
    mapLocation testLocation = iterator.next();
    mapView.getProjection().toPixels(testLocation.getPoint(), screenCoords);             
    hitTestRecr.set(-bubbleIcon.getWidth()/2,-bubbleIcon.getHeight(),bubbleIcon.getWidth()/2,0); 
    hitTestRecr.offset(screenCoords.x,screenCoords.y); 
    mapView.getProjection().toPixels(tapPoint, screenCoords);
    if (hitTestRecr.contains(screenCoords.x,screenCoords.y)) { 
    pLocation = testLocation;  
    break; } 
} 
return hitMapLocation; 
Donal Rafferty