我目前正在尝试启动一个Uri意图,以便当用户单击标记的信息窗口时,它将启动一个谷歌查询+我从Firebase获得并解析为ClusterManager的相应标记的名称。
我尝试创建一个字符串容器来在其中存储公司名称,然后添加一个谷歌查询字符串,并将其作为Uri意图传递到我的setOnInfoWindowClickListener中。
(注意: 'TheNameOfThisMarker‘实际上并没有在这里定义,我只是想给出一个我试图实现的想法’)
我的信息窗口单击Listener:
mMap.setOnInfoWindowClickListener(object : GoogleMap.OnInfoWindowClickListener {
override fun onInfoWindowClick(marker: Marker) {
val url = "http://www.google.com/#q=" + " " + (TheNameOfThisMarker)
val i = Intent(Intent.ACTION_VIEW)
i.setData(Uri.parse(url))
startActivity(i)
}
})
从Firebase加载数据:
private fun loadMarkersFromDB() {
mCompanies.child("data/results").addListenerForSingleValueEvent(object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
if (dataSnapshot.exists()) {
for (s in dataSnapshot.children) {
var company = s.getValue(Company::class.java)
val infoWindow =
MyItem(company!!.latitude, company.longitude, company.name)
mClusterManager.setAnimation(false)
if ((company.latitude < (circle.center.latitude + circle.radius) && company.latitude > (circle.center.latitude - circle.radius))
&& ((company.longitude < (circle.center.longitude + circle.radius) && company.longitude > (circle.center.longitude - circle.radius)))
) {
mClusterManager.addItem(infoWindow)
}
TheNameOfThisMarker = company!!.name
Log.d("onDataChange", company.toString())
}
}
}
override fun onCancelled(databaseError: DatabaseError) {
Log.w("MapsActivity", databaseError.toException())
}
})
}
我的集群设置:
private fun setUpCluster() {
// Initialize the manager with the context and the map.
// (Activity extends context, so we can pass 'this' in the constructor.)
mClusterManager = ClusterManager(this, mMap)
// Point the map's listeners at the listeners implemented by the cluster
// manager.
mMap.setOnCameraIdleListener(mClusterManager)
mMap.setOnMarkerClickListener(mClusterManager)
// Add cluster items (markers) to the cluster manager.
loadMarkersFromDB()
}
虽然我能够在Info窗口中执行某些操作,但我不知道如何确定每个标记的名称并将其添加到我的查询Uri意图中。
https://stackoverflow.com/questions/55347444
复制相似问题