android - get coordinates by clicking on map (openstreetmaps) -
how can coordinates of point clicking on in open street maps?
tried:
public void onclick(view v) { projection proj = mapview.getprojection(); igeopoint p = proj.frompixels(v.getx(), v.gety()); system.out.println("x: "+ v.getx() + " y: "+ v.gety()); }
cheers, thanasio
use dispatchtouchevent()
method. works because mapactivity
inherits dispatchtouch
event, not ontouchevent
activity class.
@override public boolean dispatchtouchevent(motionevent ev) { int actiontype = ev.getaction(); switch (actiontype) { case motionevent.action_up: projection proj = mapview.getprojection(); geopoint loc = proj.frompixels((int)ev.getx(), (int)ev.gety()); string longitude = double.tostring(((double)loc.getlongitudee6())/1000000); string latitude = double.tostring(((double)loc.getlatitudee6())/1000000); toast toast = toast.maketext(getapplicationcontext(), "longitude: "+ longitude +" latitude: "+ latitude , toast.length_long); toast.show(); } return super.dispatchtouchevent(ev); }
Comments
Post a Comment