immanueln2005 wrote:Hi,
I was looking towards capturing the latitude and longitude of any point I click on a map in my application.
setOnClickListener() / onTouchEvent() do not work. They are not fired when i click on the map.
onTap() dint really prove to be useful as i need to capture clicks ANYWHERE on the map.
I could not figure out how to override
Hope someone helps me out with this
Thanks,
Immanuel
hi
i am not sure. But you may try this code in your application
@Override
public void onCreate(Bundle icicl){
.............
.............
OnTouchListener myOnTouchListener=new OnTouchListener(){
public boolean onTouch(View mapView,MotionEvent m){
int action=m.getAction();
switch(action){
case MotionEvent.ACTION_UP:
int x=(int)m.getX();
int y=(int)m.getY();
double latspan=(myMapView.getLatitudeSpan()/1.0E6);
double lngspan=(myMapView.getLongitudeSpan()/1.0E6);
GeoPoint center=myMapView.getMapCenter();
double xpcent=(x/(double)myMapView.getWidth());
double ypcent=(y/(double)myMapView.getHeight());
double lat0=(center.getLatitudeE6()/1.0E6+(latspan/2.0));
double lng0=(center.getLongitudeE6()/1.0E6-(lngspan/2.0));
double lat=lat0-(ypcent*latspan);
double lng=lng0+(xpcent*lngspan);
Log.i("x=",""+x);
Log.i("y=",""+y);
GeoPoint newpoint=new GeoPoint((int)(lat*1E6),(int)(lng*1E6));
// myMapView.getController().zoomOut();
Log.i("Map","Height"+myMapView.getHeight());
Log.i("Map","width"+myMapView.getWidth());
Log.i("Current","LatitudeSpane"+myMapView.getLatitudeSpan());
Log.i("Current","LongitudeSpan"+myMapView.getLongitudeSpan());
Log.i("center Longitude","is"+newpoint.getLongitudeE6());
Log.i("center","Latitude is"+newpoint.getLatitudeE6());
Log.i("new ","latitude "+lat);
Log.i("new","longitude "+lng);
Log.i("background","is"+myMapView.getBackground());
Log.i("Zoom in","works");
myMapView.invalidate();
mc.animateTo(newpoint);
mc.zoomIn();
break;
}
return true;
}
};
myMapView.setOnTouchListener(myOnTouchListener);
......
.....
}
Regards
Sridhar.S