Reputation:
I am Google Map API V2 and Android and trying to set the onClick event for google map marker. Basically I have two sets of marker:
Bus Stop Marker
private void addBusStopMarker(){
map.addMarker(new MarkerOptions().position(new LatLng(1.28213,103.81721)).title("10009 - Bt Merah Ctrl").icon(BitmapDescriptorFactory.fromResource(R.drawable.busstopicon)).snippet("Average Commuters: 9,940"));
map.addMarker(new MarkerOptions().position(new LatLng(1.28294,103.82166)).title("10089 - Jln Bt Merah - B08").icon(BitmapDescriptorFactory.fromResource(R.drawable.busstopicon)).snippet("Average Commuters: 2,050"));
}
School Marker
private void addSchoolMarker(){
map.addMarker(new MarkerOptions().position(new LatLng(1.28515,103.81509)).title("Gan Eng Seng Primary School").icon(BitmapDescriptorFactory.fromResource(R.drawable.school)).snippet("Address: 100 RedHill Close, 158901"));
map.addMarker(new MarkerOptions().position(new LatLng(1.28555,103.81361)).title("Bt Merah Secondary School").icon(BitmapDescriptorFactory.fromResource(R.drawable.school)).snippet("Address: 100 Henderson Road, 158901"));
}
And my marker info window onClick event:
private void initilizeMap() {
if (map == null) {
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.map)).getMap();}
});
//Bus stop info window onClick event
map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Intent intent = new Intent(context ,PopulationCharts.class);
String title = marker.getTitle();
intent.putExtra("markertitle", title);
startActivity(intent);
}
});
// check if map is created successfully or not
if (map == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
Basically if the info window is clicked, it will shows charts but this is meant for bus stop marker only. However, from the codes above, even my school marker info window is on click, it will still showing charts. I wonder is there any possible way to disable the info window onclick event just for my school marker?
Thanks in advance.
Upvotes: 5
Views: 7229
Reputation: 549
You could try to check if the Marker
you are interacting with has the word "school" in its title:
@Override
public void onInfoWindowClick(Marker marker) {
Intent intent = new Intent(context ,PopulationCharts.class);
String title = marker.getTitle();
if(!title.contains("school")){ // if bus stop
intent.putExtra("markertitle", title);
startActivity(intent);
}else{
// whatever you need to do for schools
}
}
Upvotes: 2