I am currently trying to launch a Uri intent so that when the user clicks the Info Window of a marker, it will launch a google query + the name of that corresponding marker which I have obtained from Firebase and parsed into ClusterManager.
I have tried creating a String holder to store the company name inside it, and then adding it with a google query string and passing it as a Uri Intent all inside my setOnInfoWindowClickListener.
(NOTE: 'TheNameOfThisMarker' is not actually defined here, I just wanted to give an idea of what I am trying to accomplish')
My Info Window Click 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)
}
})
Loading Data from 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())
}
})
}
My Cluster setup:
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()
}
Although I am able to do something inside my Info Window Click Listener, I have no idea how to pinpoint each individual marker's name and add it into my query Uri intent.