简体   繁体   中英

Using OnMapClickListener with intent activity

My android application is calling Google Maps (using ACTION_VIEW) from my first activity.

public void goToMap(View v)
{
    Toast.makeText(this,"Button is clicked",Toast.LENGTH_SHORT).show();
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("geo:23.214889,77.3988962"));
    intent.putExtra("Id", "map");
    startActivity(intent);
}

Documentation to use GoogleMap object with OnMapClickListener is nowhere specified.

What i am trying is:

@Override
public boolean onCreateOptionsMenu(Menu menu) 
{
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);

    GoogleMap map;

    // Here--------------------------------------------
    // What object should this map object be and how should i use this.
    map.setOnMapClickListener(new OnMapClickListener() {

        @Override
        public void onMapClick(LatLng point) {
            // TODO Auto-generated method stub
            double lat = point.latitude;
            double lng = point.longitude;
        }
    });

    return true;
}

I haven't assigned an ID to the intent i am starting.

I want to use onMapClick() function for my GOOGLE MAP TOUCH EVENT. How to initialise the map object so that it can be used for click Listener event.

Please guide me through this.

Thanks.

you should call getMapAsync method. Like this:

mapFragment.getMapAsync(this);

And then:

@Override
public void onMapReady(final GoogleMap map) {
    this.map = map;
    //Set On Map Click Listener here
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM