user3018244
user3018244

Reputation: 75

Stuck trying to add an info window to a marker?

        // latitude and longitude
        double latitude1 =51.525516;
        double longitude1 =-0.460905;

     // create marker
        MarkerOptions marker1 = new MarkerOptions().position(new LatLng(latitude1,        longitude1)).title("Jack ").snippet("Hillingdon Hospital").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE));
        marker1.showInfoWindow();

        // adding marker
        googleMap.addMarker(marker1);

        // check if map is created successfully or not
        if (googleMap == null) {
            Toast.makeText(getApplicationContext(),
                    "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                    .show();
        }

the marker1.showinfowindow comes up with the error "undefined for type MarkerOptions". Basically i want to create an info window so that when you click the marker you can bring up extra info and it provides links for visiting web pages.

any help would be appreciated, thanks.

Upvotes: 0

Views: 58

Answers (1)

romtsn
romtsn

Reputation: 11992

The error appears, because you are trying to show info window with unexisting marker. You should replace your code - firstly, add marker to the googleMap, then show info window:

   // latitude and longitude
    double latitude1 =51.525516;
    double longitude1 =-0.460905;

 // create marker
    MarkerOptions markerOptions1 = new MarkerOptions().position(new LatLng(latitude1,        longitude1)).title("Jack ").snippet("Hillingdon Hospital").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE));


    // adding marker
    Marker marker1 = googleMap.addMarker(markerOptions1);
    marker1.showInfoWindow();


    // check if map is created successfully or not
    if (googleMap == null) {
        Toast.makeText(getApplicationContext(),
                "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                .show();
    }

Upvotes: 1

Related Questions