0

i have taken one radio button as GPS. now i want to show my current location when i clicked on that radio button.. how to achieve it? please give me some sample code for the same...

Thanks in Advance---

2 Answers 2

4

use this code in radiobutton onclick event.....

        Location location;
        protected LocationManager locationManager;

        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

        if (location != null) {
        String message = String.format(
                        "Current Location \n Longitude: %1$s \n Latitude: %2$s",
                        location.getLongitude(), location.getLatitude());
                Toast.makeText(LbsGeocodingActivity.this, message,
                        Toast.LENGTH_LONG).show();

                List<Overlay> mapOverlays = mapView.getOverlays();
                Drawable drawable = this.getResources().getDrawable(
                        R.drawable.new3pin);
                HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(
                        drawable, LbsGeocodingActivity.this);
            itemizedoverlay.addOverlay(overlayitem);
            mapOverlays.add(itemizedoverlay);

        } else {
            Toast.makeText(LbsGeocodingActivity.this, "No Location Found",
                    Toast.LENGTH_LONG).show();
        }

second HelloItemizedOverlay.java class..

public class HelloItemizedOverlay extends ItemizedOverlay {

    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    Context mContext;

    @Override
    protected OverlayItem createItem(int i) {
        // TODO Auto-generated method stub
        return mOverlays.get(i);
    }

    @Override
    public int size() {
        // TODO Auto-generated method stub
        return mOverlays.size();
    }


    public void addOverlay(OverlayItem overlay) {
        mOverlays.add(overlay);
        populate();
    }

    public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
        super(boundCenterBottom(defaultMarker));
        mContext = context;
    }


}
0
0

i have pasted the sample code Here

Crete one interface to notify when location is obtained.. put code in OnClick event(or onSelected) of your Radio button

LocProvider locProvider = LocProvider.getInstance(); locProvider.init(this); locProvider.initializeLocationSearch(); locProvider.setLocationCallbackListener(<crete ownlistener and assign here>);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.