Android Google Map V2 InfoWindow
-
21-12-2019 - |
Question
I am a beginner in android. I have implemented Google Map v2, but i Want a custom info Window with three button, I went through Documentation, but the default infowindow is single clickable and it cannot have buttons, any way or idea i can do this. Please help me on this.
Solution
What you are trying to achieve is possible.
You can see the recipe in this answer:Google Maps Android API v2 - Interactive InfoWindow (like in original android google maps)
And a working implementation on Google Play
And also here a small tutorial
OTHER TIPS
U need to create a custom window like this
class BalloonAdapter implements InfoWindowAdapter {
LayoutInflater inflater = null;
private Button Button1, Button2, Button3;
public BalloonAdapter(LayoutInflater inflater) {
this.inflater = inflater;
}
@Override
public View getInfoWindow(Marker marker) {
User_ID = marker.getTitle();
View v = inflater.inflate(R.layout.map_ballon, null);
if(User_ID.equals("Your location")){
//Toast.makeText(getApplicationContext(), "your location", Toast.LENGTH_LONG).show();
textViewTitle = (TextView) v.findViewById(R.id.balloon_name);
textViewTitle.setText(marker.getTitle());
}else{
if (marker != null) {
image = (ImageView) v.findViewById(R.id.balloon_image);
Button1= (Button) v.findViewById(R.id.balloon_name);
Button2 = (Button ) v.findViewById(R.id.balloon_age);
Button3 = (Button ) v.findViewById(R.id.balloon_id);
Button1.setText(marker.getTitle());
Button2.setText(marker.getSnippet());
Button3.setVisibility(View.GONE);
imageLoader.DisplayImage(ImageLoad, image);
Button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//do wat do u want with this button
}
});
Button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//do wat do u want with this button
}
});
Button3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//do wat do u want with this button
}
});
}
}
return v;
}
@Override
public View getInfoContents(Marker marker) {
return (null);
}
}
and You can call the function like this
map.addMarker(new MarkerOptions()
.position(
new LatLng(
Double.parseDouble(Latitude),
Double.parseDouble(Longitude)))
.title(User_ID + "\n" + "Name: " + CustomerName
+ "\n"+"Gender: " + Gender)
.snippet(PhoneNum+"\n"+ImageStatus+"*"+ImageLoad)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.maponinemarker)));
map.setInfoWindowAdapter(new BalloonAdapter(getLayoutInflater()));
this is how u call the infowindo map.setInfoWindowAdapter(new BalloonAdapter(getLayoutInflater()));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow