如何将Google标记设置为按钮?

时间:2014-09-29 16:32:56

标签: android google-maps

我对android编程完全陌生.. 可以将我的标记设置为按钮吗? 或设置标记以调用AlertDialog?

如果是的话,你能告诉我一些例子吗?

谢谢你!

受保护的void onCreate(Bundle savedInstanceState){

    super.onCreate(savedInstanceState);
    setContentView(R.layout.map);

    try{
        InitilizeMap();
    }catch(Exception e){
        e.printStackTrace();
    }

    MarkerOptions ponto1 = new MarkerOptions().position(new LatLng(LatPonto1, LongPonto1)).title("tittle");
    ponto1.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE));
    ponto1.infoWindowAnchor(getTitleColor(), getTaskId());
    googleMap.addMarker(ponto1);




}

2 个答案:

答案 0 :(得分:0)

您可以使用onMarkerClickListener并在其中弹出警报。

mMap.setOnMarkerClickListener(mOnMarkerClickListener);

OnMarkerClickListener mOnMarkerClickListener = new OnMarkerClickListener() {

        @Override
        public boolean onMarkerClick(Marker marker) {
            // create your dialog here.
            return false;
        }
    };

mMap是GoogleMaps的一个实例。

答案 1 :(得分:0)

感谢您的回答! 它现在正在工作,我忘了.builder并将按钮设置为中性..

  googleMap.setOnMarkerClickListener(new OnMarkerClickListener() {  
        @Override
        public boolean onMarkerClick(Marker point) {
            // TODO Auto-generated method stub
            if(point.equals(p_tur)){

                showAlertDialog();
            }
            return false;
        }
    });
}
    @SuppressWarnings("deprecation")
    void showAlertDialog(){
       AlertDialog.Builder alert = new AlertDialog.Builder(getBaseContext()).create();

         alert.setTitle("Location Selected");

            alert.setMessage("This is a message");

           alert.setNeutralButton("Place", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                   Toast.makeText(getApplicationContext(),
                           "test", Toast.LENGTH_SHORT).show();
                }
            });
            alert.show();

    }