开发者

Cannot transfer address for My Location from custom Itemized Overlay class to another Activity

I have a small problem with android maps. I added an ItemizedOverlay class to display my custom marker. When i click on the marker i want to go on another activity on witch i will show the address of the marker witch marks my location. here is the code i am using in the itemizedOverlay class to get the address:

  public void getAddressForLocation(final Double lat, final Double lng){
    Thread thr = new Thread(){
        public void run(){
            try{
                gc1 = new Geocoder(mContext);
                adresi = gc1.getFromLocation(lat, lng, 4);
                uiCallback.sendEmptyMessage(0);
            }catch(IOE开发者_Python百科xception e){
                e.printStackTrace();
            }
        }
    };
    thr.start();
}

private Handler uiCallback = new Handler(){
        @Override
        public void handleMessage(Message msg){
            if(adresi != null && adresi.size() > 0){
                StringBuilder sb = new StringBuilder();
                Address adresa1 = adresi.get(0);
                for(int i = 0; i < adresa1.getMaxAddressLineIndex(); i++){
                    sb.append(adresa1.getAddressLine(i)).append(" ");
                    myAddress = sb.toString();
                    Log.v("addr", myAddress);
                }
            }
            else{

            }
        }
    };

    @Override 
    public boolean onTap(int index){

        OverlayItem item = getItem(index);
        GeoPoint p1 = item.getPoint();
        Double lat1 = p1.getLatitudeE6()/1E6;
        Double lon1 = p1.getLongitudeE6()/1E6;
        getAddressForLocation(lat1, lon1);

        Intent i = new Intent();
        i.setClass(mContext, Tagging.class);
        b = new Bundle();
        b.putString("adresa", myAddress);
        i.putExtras(b);
        mContext.startActivity(i);
        return true;
    }

i get the address in the LogCat but on the other activity i dot get anything and there are no errors. i could not find examples abouth this problem and i am new to all this so any help will be very appreciated thanks in advance


What happens when you tap the overlay before the thread with the addresses finishes? I think there is a little race condition or something.

Why does the overlay has to know the address? I would simply pass the lat and lng values to the new activity and let the activity determine the address.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜