我的新应用程序基于Google Maps活动。我将onMapLongClickListener设置为添加与用户想要的一样多的新标记。但是我的问题是:我想在地图的顶部设置一个ListView,以便用户可以在不同的标记类型之间进行选择。如何设置当我在地图上保持一个点时出现的ListView,然后在选择其中一个项目后消失?
这是我的应用代码,如果它可以帮助您给我一些解决方案!
MapsActivity.java
<script>
$(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip();
$('#payment-form').formValidation({
framework: 'bootstrap',
trigger: 'change',
fields: {
first_name: {
validators: {
notEmpty: {
message: 'The First Name field is required and cannot be empty'
}
// regexp: {
// regexp: /^[a-z\\s]+$/i,
// message: 'The first name field can consist of alphabetical characters and spaces only'
// }
}
},
last_name: {
validators: {
notEmpty: {
message: 'The Last Name is required and cannot be empty'
}
// regexp: {
// regexp: /^[a-z\\s]+$/i,
// message: 'The Last name can consist of alphabetical characters and spaces only'
// }
}
},
}
});
}).on('success.form.fv', function (e) {
$('#continue_btn').attr('disabled','false');
e.preventDefault();
});
var i = 0;
var l=0;
$('#zip_code').keydown(function()
{
var country_check = $('#country').val();
if(country_check=='India')
{
$('#zip_code').attr('maxlength', '6');
}
else
{
$('#zip_code').attr('maxlength', '10');
}
});
</script>
activity_maps.xml
package com.example.mancu_000.onclickmarkerlistener;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, OnMapLongClickListener {
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
map.setOnMapLongClickListener(this);
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
Toast.makeText(MapsActivity.this, "OnMarkerListener", Toast.LENGTH_SHORT).show();
return true;
}
});
LatLng home = new LatLng(44.42913, 8.84072);
map.addMarker(new MarkerOptions().position(home).title("Home, bitches!"));
map.moveCamera(CameraUpdateFactory.newLatLng(home));
CameraUpdate center = CameraUpdateFactory.newLatLng(home);
map.moveCamera(center);
CameraUpdate zoom = CameraUpdateFactory.zoomTo(17);
map.animateCamera(zoom);
}
@Override
public void onMapLongClick(LatLng location) {
// Here I'm supposed to implements thee code of the ListView on the top of the map
}
}
感谢您的支持!!
答案 0 :(得分:0)
按对话框获取
等标记列表@Override
public void onMapLongClick(LatLng location) {
AlertDialog.Builder builderSingle = new AlertDialog.Builder(context);
builderSingle.setIcon(R.drawable.title_icon_resource);
builderSingle.setTitle("Select One Name:-");
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>();//create adapter with your markers list
builderSingle.setNegativeButton();//to exit directly if you want
builderSingle.setAdapter(arrayAdapter,new DialogInterface.OnClickListener());//set your adapter and listener
builderSingle.show();
}
希望这会对你有所帮助