0

I have placed a marker on my Google Map in android, what I want to be able to do is when it gets touched a image to show above it, marker stays there and the title, snippet etc. as well and a image displays. I have been searching the net and could not find any solution. Also is it possible when the image appears and if the user clicks on it performs an action e.g. goes to another page, enlarges the image etc.

private GoogleMap mMap;
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.addMarker(new MarkerOptions()
        .position(new LatLng(10, 10))
        .title("Hello world"));

Thanks.

Android
  • 171
  • 1
  • 4
  • 16
  • You'll probably go with `Custom Info Window Marker`.. Search on `Google` for that ....You'll get many example.... – M D Dec 01 '14 at 06:32

4 Answers4

0
Googel Map With coustem image


 mSydney = mMap.addMarker(new MarkerOptions()
.position(SYDNEY)
.title("Sydney")
.snippet("Population: 4,627,300")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)));

and also

private static final LatLng MELBOURNE = new LatLng(-37.813, 144.962);
   private Marker melbourne = mMap.addMarker(new MarkerOptions()
                            .position(MELBOURNE)
                            .title("Melbourne")
                            .snippet("Population: 4,137,400")
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)));

Googel Map With coustem image

Customize the marker image

Community
  • 1
  • 1
Naveen Tamrakar
  • 3,349
  • 1
  • 19
  • 28
0

You have to use android Utils to place image on the google map marked place. Check this link for complete code.

public class IconGeneratorDemoActivity extends BaseDemoActivity {

@Override
protected void startDemo() {
    getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.8696, 151.2094), 10));

    IconGenerator iconFactory = new IconGenerator(this);
    addIcon(iconFactory, "Default", new LatLng(-33.8696, 151.2094));

    iconFactory.setStyle(IconGenerator.STYLE_BLUE);
    addIcon(iconFactory, "Blue style", new LatLng(-33.9360, 151.2070));

    iconFactory.setRotation(90);
    iconFactory.setStyle(IconGenerator.STYLE_RED);
    addIcon(iconFactory, "Rotated 90 degrees", new LatLng(-33.8858, 151.096));

    iconFactory.setContentRotation(-90);
    iconFactory.setStyle(IconGenerator.STYLE_PURPLE);
    addIcon(iconFactory, "Rotate=90, ContentRotate=-90", new LatLng(-33.9992, 151.098));

    iconFactory.setRotation(0);
    iconFactory.setContentRotation(90);
    iconFactory.setStyle(IconGenerator.STYLE_GREEN);
    addIcon(iconFactory, "ContentRotate=90", new LatLng(-33.7677, 151.244));
}

private void addIcon(IconGenerator iconFactory, String text, LatLng position) {
    MarkerOptions markerOptions = new MarkerOptions().
            icon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon(text))).
            position(position).
            anchor(iconFactory.getAnchorU(), iconFactory.getAnchorV());

    getMap().addMarker(markerOptions);
}
  }
Nirmal
  • 2,340
  • 21
  • 43
0

You can use custom images for your marker

else you need to set marker listener and you need to add another view to show the image expanded or any other you need to do...

public mapActivity extends Activity implements OnMarkerClickListener{

    public GoogleMap mMap;
    mMap.setOnMarkerClickListener(this);


    @Override
    public boolean onMarkerClick(Marker marker) {
          //Here you can show your own view to display image 
          //else you can call another activity etc...
    }
}
0

Add custom InfoWindow Marker in your code :

    class MyInfoWindowAdapter implements InfoWindowAdapter {

        private final View myContentsView;

        MyInfoWindowAdapter() {
            myContentsView = getLayoutInflater().inflate(R.layout.map_popup,
                    null);
        }

        @Override
        public View getInfoContents(Marker marker) {

            TextView tvTitle = ((TextView) myContentsView
                    .findViewById(R.id.title));
            tvTitle.setText(marker.getTitle());
            TextView tvSnippet = ((TextView) myContentsView
                    .findViewById(R.id.snippet));
            ImageView ivIcon = ((ImageView) myContentsView
                    .findViewById(R.id.icon));
            tvSnippet.setText(marker.getSnippet());

            return myContentsView;
        }

        @Override
        public View getInfoWindow(Marker marker) {
            // TODO Auto-generated method stub
            return null;
        }

    }

    @Override
    public void onInfoWindowClick(Marker arg0) {
        Toast.makeText(GoogleMapActivity.this, "Marker Info Window clicked",
                Toast.LENGTH_SHORT).show();
    }

in your onCreate() method, add below line:

googleMap.setInfoWindowAdapter(new MyInfoWindowAdapter());
Karan Maru
  • 991
  • 6
  • 17