简体   繁体   English

结合使用InMapClickListener和意图活动

[英]Using OnMapClickListener with intent activity

My android application is calling Google Maps (using ACTION_VIEW) from my first activity. 我的Android应用程序在我的第一个活动中正在调用Google Maps(使用ACTION_VIEW)。

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. 没有在任何地方指定将GoogleMap对象与OnMapClickListener一起使用的文档。

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. 我尚未为要开始的意图分配ID。

I want to use onMapClick() function for my GOOGLE MAP TOUCH EVENT. 我想对我的GOOGLE MAP TOUCH EVENT使用onMapClick()函数。 How to initialise the map object so that it can be used for click Listener event. 如何初始化地图对象,使其可以用于Click Listener事件。

Please guide me through this. 请指导我。

Thanks. 谢谢。

you should call getMapAsync method. 您应该调用getMapAsync方法。 Like this: 像这样:

mapFragment.getMapAsync(this);

And then: 接着:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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