将 OnMapClickListener 与意图活动一起使用



我的安卓应用程序从我的第一个活动中调用谷歌地图(使用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);
}

GoogleMap对象与OnMapClickListener一起使用的文档没有指定。

我正在尝试的是:

@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;
}

我尚未为要启动的意图分配 ID。

我想将onMapClick()函数用于我的GOOGLE MAP TOUCH EVENT。如何初始化映射对象,以便它可以用于单击侦听器事件。

请指导我完成此操作。

谢谢。

你应该调用getMapAsync方法。喜欢这个:

mapFragment.getMapAsync(this);

然后:

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

最新更新