开发者

Android MapActivity onTap event

开发者 https://www.devze.com 2023-03-27 13:18 出处:网络
I have 开发者_开发问答a MapActivity and Map pins are displayed using ItemizedOverlay. I want to transfer onTap event to MapActivity. (onTap function is present in ItemizedOverlay class). How this can

I have 开发者_开发问答a MapActivity and Map pins are displayed using ItemizedOverlay. I want to transfer onTap event to MapActivity. (onTap function is present in ItemizedOverlay class). How this can be done?


class CurOverlay extends Overlay
 {
   private GeoPoint pointToDraw;
    String addstr,addcity;
   @Override
    public boolean onTap(GeoPoint p, MapView mapView) {
        // TODO Auto-generated method stub

      final double taplat,taplon;
        taplat=p.getLatitudeE6()/1E6;
       taplon=p.getLongitudeE6()/1E6;



            Geocoder geo = new Geocoder(getApplicationContext(), Locale.getDefault());
            List<Address> add;
            try
            {

                add = geo.getFromLocation(taplat,taplon,1);

                Log.i("ADD OBJ SIZE IS----",""+add.size());
                if (add.size() > 0) 
                {

                    addstr = add.get(0).getAddressLine(0)+" "+add.get(0).getAddressLine(1);
                }
}
catch (IOException e) 
            {

                e.printStackTrace();
            }

        return super.onTap(p, mapView);
    }
 public void setPointToDraw(GeoPoint point) {
     pointToDraw = point;
   }


   public GeoPoint getPointToDraw() {
     return pointToDraw;
   }
}

Just add this code to your tapactivity and call it from other activity (by ActivityforResult) and get the location there simple....

0

精彩评论

暂无评论...
验证码 换一张
取 消