现在,我的应用可以搜索地点,当我搜索地点时,它们会在现场标记。但是我想让用户确认他们是否真的要在那里做标记。搜索时,是否有一种方法可以在标记上显示带有“否”复选框的弹出信息? 我知道单击标记时会有一个默认的信息窗口。但是我想在信息窗口上做一个按钮,例如“您想在这里做一个标记吗?”问题,那里有一个是或否按钮。 另外,如果我可以制作popupinfo之类的东西,我想想一种方法来在用户想要删除标记时 有什么想法吗?
这是我的Java代码
package com.example.yoons.honey;
public class RealMap extends AppCompatActivity implements OnMapReadyCallback, GoogleMap.OnMarkerClickListener {
private Button searchButton;
GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.real_map);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync((OnMapReadyCallback) this);
searchButton = new Button(this);
searchButton.setOnClickListener(search);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap =googleMap;
mMap.setOnMarkerClickListener(this);
/*LatLng sydney = new LatLng(-33.852, 151.211);
googleMap.addMarker(new MarkerOptions().position(sydney)
.title("Marker in Sydney"));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));*/
}
private View.OnClickListener search=new View.OnClickListener(){ //검색버튼
public void onClick(View v){
onMapSearch(v);
}
};
public void onMapSearch(View view) {
int markercount=0;//주소개수 사용
EditText locationSearch = (EditText) findViewById(R.id.editText);
String location = locationSearch.getText().toString();
List<Address> addressList = null;
if (location != null || !location.equals("")) {
Geocoder geocoder = new Geocoder(this);
try {
addressList = geocoder.getFromLocationName(location, 1);
} catch (IOException e) {
e.printStackTrace();
}
if (addressList != null && addressList.size() != 0) {
Address address = addressList.get(0);
LatLng latLng = new LatLng(address.getLatitude(), address.getLongitude());
mMap.addMarker(new MarkerOptions().position(latLng).title("Marker")/*.draggable(true)*/);
markercount++;
// mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15f));
} else {
Toast.makeText(getApplicationContext(), "location not found", Toast.LENGTH_SHORT).show();
}
}
}
@Override
public boolean onMarkerClick(Marker marker) {
return false;
}
}
答案 0 :(得分:0)
Query query = new Query.Builder()
.addFilter(Filters.eq(SearchableField.TITLE, "HelloWorld.txt"))
.build();
Task<MetadataBuffer> queryTask = getDriveResourceClient().query(query);
此行执行添加标记操作。因此,您可以做的是创建alertdialog并在onclicklistener中处理“是”。
mMap.addMarker(new MarkerOptions().position(latLng).title("Marker")
并在您的onMapSearch函数中,像这样构建警报对话框。
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case DialogInterface.BUTTON_POSITIVE:
//Yes button clicked
mMap.addMarker(new MarkerOptions().position(latLng).title("Marker");
markercount++;
// mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15f));
break;
case DialogInterface.BUTTON_NEGATIVE:
//No button clicked
break;
}
}
};