cross_fire
cross_fire

Reputation: 539

Google Maps Android API v2 - detect long click on map AlertDialog

I am trying to create one app,when I click longer in to the screen I want to pop up a AlertDialog.

I wrote some code but gives errors.

Sorry for my bad english.

Thanks in advance.

public class Maps extends FragmentActivity    {

   private GoogleMap map;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

map = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();  


        map.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {

            @Override
            public void onMapLongClick(LatLng point) {
                // TODO Auto-generated method stub


          AlertDialog alert = new AlertDialog.Builder(Maps.this).create();
             alert.setTitle("Choose option");

             alert.setButton("Satellite",new DialogInterface.OnClickListener() {



        @Override
        public void onClick(DialogInterface dialog, int which) {
        // TODO Auto-generated method stub

                  map.setMapType(GoogleMap.MAP_TYPE_HYBRID);         

                    }

                });

            }
        });

           }
     }

Upvotes: 1

Views: 1666

Answers (1)

Simo
Simo

Reputation: 1230

you can add alert.show(); at the end of your code

Upvotes: 1

Related Questions