2

I am trying to have a default map marker in google map fragment and want to show some text next to it like the one shown in the pic below.

I have tried http://googlemaps.github.io/android-maps-utils/ library however, it is not giving me the desired affect. Also I have a separate infowindow which pops up when the user clicks on the marker or the text next to it.

Google map marker with text

Google map info window

Can anybody please point me to any material or reference to achieve the above.

Nav
  • 10,304
  • 20
  • 56
  • 83
  • [Check if this helps](http://stackoverflow.com/q/17837510/1777090) – MysticMagicϡ Jun 30 '14 at 11:29
  • yup saw that one.. uses the google maps utility library .. wanna know how to achieve something like the default map using that library or any other thats available – Nav Jun 30 '14 at 11:30

2 Answers2

1

If you wanna show the info window without requiring user tap then

Marker.showInfoWindow() will work if Marker.visible is set to true.

Otherwise there is a good library here with an example here This may be closer to what you are looking for.

Reference

Rachel Gallen
  • 27,943
  • 21
  • 72
  • 81
  • also see answer with 44 votes here http://stackoverflow.com/questions/13763545/android-maps-api-v2-with-custom-markers – Rachel Gallen Jun 30 '14 at 11:47
  • how can i customize the text to be shown next to the marker instead of in the middle of the marker ??? – Nav Jun 30 '14 at 12:02
  • @Nav could you set the x and y position? take a look at the other answer and see if that helps – Rachel Gallen Jun 30 '14 at 12:04
  • Sorry If i didnt made it clear earlier but I ain't talking about the infowindow. The marker will have some text next to it and clicking on any one of them will bring up the info window. I have already done the info window just need to somehow position a label of sorts next to the marker icon – Nav Jun 30 '14 at 12:25
  • Please see the new image I have attached to the question , it shows an infowindow when u hover or click the label next to the marker. I want to achieve something similar – Nav Jun 30 '14 at 12:30
  • umm those are javascript libraries i presume.. is there anything similar for java, i mean android ??? Thanks though for the help :) – Nav Jun 30 '14 at 14:10
  • well gotta go with the canvas thingy for now as there is no official support for it seems :( – Nav Jul 02 '14 at 08:50
0

You can use info window adapter for this purpose , you can also customize the info window by giving your own custom layout

mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
        // Use default InfoWindow frame
        @Override
        public View getInfoWindow(Marker arg0) {
            return null;
        }

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

            // Getting view from the layout file info_window_layout
            View v =  getParent().getLayoutInflater().inflate(R.layout.windowlayout, null);

            // Getting the position from the marker
            LatLng latLng = arg0.getPosition();

            // Getting reference to the TextView to set latitude
             tvLat = (TextView) v.findViewById(R.id.tv_lat);

            // Setting the latitude
            tvLat.setText(duration);

            // Returning the view containing InfoWindow contents
            return v;
        }
    });

here is the custom windowlayout , you can use your own

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
    android:id="@+id/tv_lat"
    android:layout_width="wrap_content"
    android:text="latitude"
    android:drawableRight="@drawable/ic_launcher"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"/>

Mehroz Munir
  • 2,248
  • 1
  • 18
  • 16