簡體   English   中英

結合使用InMapClickListener和意圖活動

[英]Using OnMapClickListener with intent 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);
}

沒有在任何地方指定將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。

我想對我的GOOGLE MAP TOUCH EVENT使用onMapClick()函數。 如何初始化地圖對象,使其可以用於Click Listener事件。

請指導我。

謝謝。

您應該調用getMapAsync方法。 像這樣:

mapFragment.getMapAsync(this);

接着:

@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