Change The Icon / Image Marker Google Map ( Ganti Marker Google Map Android )


How the way to change the icon of marker in Google Map Android? It is simple guys, Look the code below. This is the solution if we want to change just the color of marker.


Bagaimana cara mengganti icon marker di Google Map Android? Caranya cukup simple. Lihat kode berikut ini. Untuk kode ini marker diganti warna yang sebelumnya defaultnya merah, diubah menjadi warna hijau.



 private void drawMarker2(LatLng point, String keterangan) {

		LatLng tambah = new LatLng(point.latitude, point.longitude);
		MarkerOptions options = new MarkerOptions();
		options.position(tambah);
		options.icon(BitmapDescriptorFactory
				.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
		options.title(keterangan);
		options.snippet("Posisi " + keterangan);
		googleMap.addMarker(options);
	}


This is solution if we want to change the icon with the image / icon that we have provided in the folder res / drawable/


Sedangkan kode ini mengganti icon menjadi icon tertentu yang telah kita sediakan di folder drawable.



 private void drawMarker(LatLng point,String nama, String keterangan) {

		LatLng tambah = new LatLng(point.latitude, point.longitude);
		// Creating MarkerOptions
		MarkerOptions options = new MarkerOptions();
		options.position(tambah);
		options.icon(BitmapDescriptorFactory.fromResource(R.drawable.icon2));
		options.title(nama);
		options.snippet(keterangan);
		googleMap.addMarker(options);
	}

We just call the function like "drawMarker(posisi, "Title", "Info Marker");"

Post a Comment

أحدث أقدم