public class MapaViagem extends FragmentActivity { private GoogleMap GoogleMap; private String rm_IDViagem; private List<ClIEnteModel> mClIEnteModel = new ArrayList<ClIEnteModel>(); private List<EnderecoModel> mEnderecoModel = new ArrayList<EnderecoModel>(); private Viagemmodel mViagemmodel = new Viagemmodel(); private ClusterManager<MyItem> mClusterManager; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.maps); ArrayList<LatLng> coordList = new ArrayList<LatLng>(); try { Bundle parametros = getIntent().getExtras(); rm_IDViagem = parametros.getString("ID_viagem"); Repositorio ca = new Repositorio(this); mViagemmodel = ca.getViagemPorID(Integer.valueOf(rm_IDViagem)); Repositorio cl = new Repositorio(this); mClIEnteModel = cl.getClIEntesViagem(Integer.valueOf(rm_IDViagem)); int i; for ( i = 0; i < mClIEnteModel.size(); i++) { Repositorio mRepositorio = new Repositorio(this); mEnderecoModel = mRepositorio.getListaEnderecosDoClIEnte(Integer.valueOf(mClIEnteModel.get(i).getClIEntes_ID())); System.out.println("NOMES " + mClIEnteModel.get(i).getNome()); for (int j = 0; j < mEnderecoModel.size(); j++) { // Loading map initilizeMap(); // Changing map type GoogleMap.setMapType(GoogleMap.MAP_TYPE_norMAL); // GoogleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); // GoogleMap.setMapType(GoogleMap.MAP_TYPE_SATELliTE); // GoogleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN); // GoogleMap.setMapType(GoogleMap.MAP_TYPE_NONE); // Showing / hIDing your current location GoogleMap.setMyLocationEnabled(true); // Enable / disable zooming controls GoogleMap.getUiSettings().setZoomControlsEnabled(true); // Enable / disable my location button GoogleMap.getUiSettings().setMyLocationbuttonEnabled(true); // Enable / disable Compass icon GoogleMap.getUiSettings().setCompassEnabled(true); // Enable / disable Rotate gesture GoogleMap.getUiSettings().setRotateGesturesEnabled(true); // Enable / disable zooming functionality GoogleMap.getUiSettings().setZoomGesturesEnabled(true); final float latitude = float.parsefloat(mEnderecoModel.get(j).getLatitude()); final float longitude = float.parsefloat(mEnderecoModel.get(j).getLongitude()); coordList.add(new LatLng(latitude,longitude)); GoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude,longitude),10)); // Initialize the manager with the context and the map. // (Activity extends context,so we can pass 'this' in the constructor.) mClusterManager = new ClusterManager<MyItem>(this,GoogleMap); // Point the map's Listeners at the Listeners implemented by the cluster // manager. GoogleMap.setonCamerachangelistener(mClusterManager); GoogleMap.setonMarkerClickListener(mClusterManager); addItems(coordList); GoogleMap.setonMarkerClickListener(new GoogleMap.OnMarkerClickListener() { @OverrIDe public boolean onMarkerClick(final Marker marker) { LatLng pos = marker.get@R_403_4612@(); int arryList@R_403_4612@ = getArrayList@R_403_4612@(pos); return true; } }); } } } catch (Exception e) { e.printstacktrace(); } } private int getArrayList@R_403_4612@(LatLng pos) { for (int i = 0; i < mEnderecoModel.size(); i++) { if (pos.latitude == Double.parseDouble(mEnderecoModel.get(i).getLatitude().split(",")[0])) { if (pos.longitude == Double.parseDouble(mEnderecoModel.get(i).getLongitude().split(",")[1])) return i; } } return 0; } private voID addItems(List<LatLng> markers) { for (int i = 0; i < markers.size(); i++) { MyItem offsetItem = new MyItem(markers.get(i)); mClusterManager.addItem(offsetItem); } } private voID initilizeMap() { if (GoogleMap == null) { GoogleMap = ((MapFragment) getFragmentManager().findFragmentByID( R.ID.map)).getMap(); // check if map is created successfully or not if (GoogleMap == null) { Toast.makeText(getApplicationContext(),"Não foi possível carregar o mapa",Toast.LENGTH_SHORT) .show(); } } } @OverrIDe protected voID onResume() { super.onResume(); initilizeMap(); }}解决方法 不确定你是如何初始化你的标记因为你没有显示代码的一部分但是在其上放置标题是这样做的:
//You need a reference to a GoogleMap objectGoogleMap map = ... // get a map.Marker marker = map.addMarker(new MarkerOptions() .@R_403_4612@(new LatLng(37.7750,122.4183)) //Or whatever coordinate .Title("Your Title") .snippet("Extra info"));
就是这样,当你点击它时,你会看到那个标记的信息.
您可以在here找到更多信息
编辑
对于ClusterManagerI认为您可以找到this answer有用
总结以上是内存溢出为你收集整理的Android setOnMarkerClickListener为每个标记设置标题全部内容,希望文章能够帮你解决Android setOnMarkerClickListener为每个标记设置标题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)