Dev bluCursor
Dev bluCursor

Reputation: 61

Create a custom shape of title bar of marker in maps in android

I am using the following code, it gives a default rectangular shape.I want to change the shape of the title bar, as in the image

enter image description here

CameraPosition cameraPos = new CameraPosition.Builder()
                    .target(ll)
                    .zoom(18).bearing(300).tilt(45).build();
         googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPos), null);

            if(racecourseroadmarker!=null)
                racecourseroadmarker.remove();
            racecourseroadmarker = googleMap.addMarker(new MarkerOptions()
                    .position(new LatLng(ll.latitude, ll
                            .longitude)).anchor(0.5f, 0.5f).draggable(true)
                    .title(getIntent().getStringExtra("busno")).snippet(location)
                    .icon(BitmapDescriptorFactory
                            .fromResource(R.drawable.bus)));

            onMarkerDragStart(racecourseroadmarker);
            onMarkerDrag(racecourseroadmarker);
            racecourseroadmarker.showInfoWindow();

Upvotes: 1

Views: 663

Answers (1)

Amitsharma
Amitsharma

Reputation: 1576

Try with this code it will help you to create custom view at google map marker snipt or title inside you can declare

View ll; 
ll = getActivity().getLayoutInflater().inflate(R.layout.markerpopup, null);
tviNamePopup = (TextView) ll.findViewById(R.id.tviNamePopup);

    googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {
        @Override
        public View getInfoWindow(Marker markerss) {
            // TODO Auto-generated method stub

            String title = markerss.getTitle();
            tviNamePopup.setText(title);
            return null;
        }

        @Override
        public View getInfoContents(Marker markerss) {
            // TODO Auto-generated method stub

            // do something here

            return ll;
        }
    });

    googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLngs));
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(2));

layout is : markerpopup.xml

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:background="@drawable/editstyle"
   android:orientation="vertical" >

   <TextView
    android:id="@+id/tviNamePopup"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="10dp"
    android:textColor="#0000FF" />

</LinearLayout>

Upvotes: 4

Related Questions