TheDevMan
TheDevMan

Reputation: 5954

Custom Info Window for Google Maps v2

I am trying out custom info Window and show it upon loading map. Custom Info Window comes up but, along with the default infowindow background (white) and also I haven't set icon for the marker it comes up? Why am I getting even that is this default?

Here is the screen shot of what I trying out:

enter image description here

I don't want the white window and marker icon? I am trying achieve something like the screenshot given in this: How to create a custom-shaped bitmap marker with Android map API v2

Here is what I am trying:

public class Mapstwo extends Fragment implements GoogleMap.OnMyLocationChangeListener
{
private GoogleMap googleMap;
private GPSTracker gps;
private double curlat;
private double curlong;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,  Bundle savedInstanceState) 
{
    if (rootView != null) 
    {
        ViewGroup parent = (ViewGroup) rootView.getParent();
        if (parent != null)
            parent.removeView(rootView);
    }
    try 
    {
        rootView = inflater.inflate(R.layout.activity_locate_me_maps, container, false);
    } 
    catch (InflateException e) 
    {

    }

            if (initMap())
    {
        gps = new GPSTracker(fa);
        curlat = gps.getLatitude();
        curlong = gps.getLongitude();
        gps.stopUsingGPS();

        myLocation(curlat, curlong, username, imageURL, ZOOMVALUE);
    }
    else
    {
        Toast.makeText(getActivity().getApplicationContext(),"Sorry! Map not available!", Toast.LENGTH_SHORT).show();
    }


    return rootView;
}


    private boolean initMap() 
{
    if (googleMap == null)
    {
        SupportMapFragment mapFrag = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map));
        googleMap = mapFrag.getMap();
        googleMap.setTrafficEnabled(true);
        //googleMap.setMyLocationEnabled(true);
        googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        googleMap.setOnMyLocationChangeListener(this);
    }

    return (googleMap != null);
}


    //MY LOCATION
private void myLocation(double lat, double lng, String name, String url, float zoom)
{

    final String uname = name; 
    curlat = getLat; 
    curlong = getLong;
    LatLng position = new LatLng(curlat, curlong);

    markermylocation = googleMap.addMarker(new MarkerOptions().position(position).title(uname).snippet("Testing is everthing OK?")); 
    markers.put(markermylocation.getId(), imageURL);
    googleMap.setInfoWindowAdapter(new CustomInfoWindowAdapter()); 
    markermylocation.showInfoWindow();

}


    @SuppressLint("InflateParams") 
private class CustomInfoWindowAdapter implements InfoWindowAdapter 
{
    @Override
    public View getInfoWindow(Marker arg0) 
    {
        return null;
    }

    @Override
    public View getInfoContents(Marker marker) 
    {
        View v = getActivity().getLayoutInflater().inflate(R.layout.activity_map, null);  

        Log.e("View","Sucessful");

        return v;
    }
}

}

Upvotes: 1

Views: 1684

Answers (1)

prakash
prakash

Reputation: 1413

try this code,you need to change the default layout frame,you need to set the your inflate view in getInfoWindow()

// Use default InfoWindow frame
    @Override
    public View getInfoWindow(Marker arg0) {
        View v = getActivity().getLayoutInflater().inflate(R.layout.activity_map, null);                                                                              
        Log.e("View","Sucessful");
        return v;
    }

   // Defines the contents of the InfoWindow
    @Override
    public View getInfoContents(Marker arg0) {
       return null;
     }

you have the inflate the view in default contents layout,so change to inflate the views.

Upvotes: 1

Related Questions