Android Google Maps API,命名标记?

时间:2015-06-05 16:28:48

标签: android google-maps

用户如何在创建标记时输入文本,以便标记获取用户输入的名称?像AlertDialog? 这是标记创建代码:

googleMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {

        @Override
        public void onMapLongClick(LatLng point) {

            // TODO Auto-generated method stub
            googleMap.addMarker(new MarkerOptions()
                    .position(point)
                    .title("Hello world"));


        }

1 个答案:

答案 0 :(得分:0)

您可以使用此代码段

  googleMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {

            @Override
            public void onMapLongClick(final LatLng point) {

               AlertDialog.Builder builder = new AlertDialog.Builder(this);
               builder.setTitle("Title");

              // Set up the input
              final EditText input = new EditText(this);
              builder.setView(input);

              // Set up the buttons
              builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                             String text = input.getText().toString();
                             googleMap.addMarker(new MarkerOptions()
                             .position(point)
                             .title(text));
              }
              });
           builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
           }
           }); 
           builder.show();      
}