2

How to Set background image of a custom google map marker? this question is not about the marker mentioned in the above question link

its about the background of a land

As we set background image to google map makers is there anyway to set a background image to highlight a special Continent using android?

any help or a reference

Community
  • 1
  • 1
Sisara Ranasinghe
  • 131
  • 1
  • 2
  • 11

3 Answers3

3

Instantiate a new GroundOverlayOptions object.

Specify the image as a BitmapDescriptor. Set the position of the image using one of the available methods:

position(LatLng location, float width, float height)
position(LatLng location, float width)
positionFromBounds(LatLngBounds bounds)

Set any optional properties, such as transparency, as desired.

Call GoogleMap.addGroundOverlay() to add the image to the map.

Refer this and this

0x5050
  • 1,221
  • 1
  • 17
  • 32
2

You need to draw a polygon by selecting some points on map.

Example code :

public class MainActivity extends FragmentActivity implements
    OnMapClickListener, 
    OnMapLongClickListener, 
    OnMarkerClickListener {

    private GoogleMap myMap;
    Location myLocation;
    boolean markerClicked;
    PolygonOptions polygonOptions;
    Polygon polygon;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        FragmentManager manager = getSupportFragmentManager();
        SupportMapFragment mapFragment = (SupportMapFragment) manager
            .findFragmentById(R.id.map);
        myMap = mapFragment.getMap();
        myMap.setMyLocationEnabled(true);
        myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        myMap.setOnMapClickListener(this);
        myMap.setOnMapLongClickListener(this);
        myMap.setOnMarkerClickListener(this);
        markerClicked = false;
    }

    @Override
    public void onMapLongClick(LatLng point) 
    {
        myMap.addMarker(new MarkerOptions()
            .position(point).title(point.toString()));

        markerClicked = false;
    }

    @Override
    public boolean onMarkerClick(Marker marker) 
    {

        if(markerClicked)
        {
            if(polygon != null)
            {
                polygon.remove();
                polygon = null;
            }

            polygonOptions.add(marker.getPosition());
            polygonOptions.strokeColor(Color.BLACK);
            polygonOptions.strokeWidth(5);
            polygonOptions.fillColor(0x884d4d4d);

            polygon = myMap.addPolygon(polygonOptions);
            marker.remove();

        }
        else    
        {
            if(polygon != null)
            {
                polygon.remove();
                polygon = null;
            }

            polygonOptions = new PolygonOptions().add(marker.getPosition());
            markerClicked = true;
            marker.remove();
        }

        return true;
    }

    @Override
    public void onMapClick(LatLng point) 
    {
        Toast.makeText(getApplicationContext(), 
            "Long Press to select locations", Toast.LENGTH_LONG).show();
    }
}

using this fragment

fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment" />

Also read the official Documentation here.

0x5050
  • 1,221
  • 1
  • 17
  • 32
  • is there any way to add a background image to a area .. as an example if we separate Australia is there any way to add a background image rather than adding a polygon or a color – Sisara Ranasinghe Feb 02 '16 at 06:19
  • ok what you want is to use is GroundOverlay . Check my new ans. – 0x5050 Feb 02 '16 at 06:45
1

Replace codes in getInfoContents with getInfoWindow. The difference between them is getInfoContents wraps your View in ViewGroup with default background. try this one

Community
  • 1
  • 1
Nuke
  • 406
  • 3
  • 13