I'm trying to change the color of a marker.
I have this:
private void addMarker(GoogleMap map, double lat, double lon,
int title, int snippet) {
map.addMarker(new MarkerOptions().position(new LatLng(lat, lon))
.title(getString(title))
.snippet(getString(snippet)));
and then this to add a marker:
addMarker(map, 40.748963847316034, -73.96807193756104,
R.string.title, R.string.snippet);
I want to change the color of the marker and I thought it would be easy and just implement it like this:
private void addMarker(GoogleMap map, double lat, double lon,
int title, int snippet, int icon) {
map.addMarker(new MarkerOptions().position(new LatLng(lat, lon))
.title(getString(title))
.snippet(getString(snippet))
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.(getString(icon)));
and:
addMarker(map, 40.748963847316034, -73.96807193756104,
R.string.title, R.string.snippet, HUE_AZURE);
But I can't use "getString" together with ".icon" apparently.
How can I do this?
Also, is that method of changing color supported for API 8+? I've had lots of problems supporting API 8+ and it would suck if this broke something...
here is a loop where I set markers with different colors on the map and it works great for me:
for (Task tempTask : TasksListAppObj.getInstance().tasksRepository.getTasksRepository())
{
LatLng latlng = new LatLng(tempTask.getLatitude(), tempTask.getLongtitude());
if (tempTask.getStatus().contentEquals(TasksListActivity.STATUS_WAITING))
{
newmarker = map.addMarker(new MarkerOptions().position(latlng).title(tempTask.getTitle()).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_for_map_blue)));
}
else if (tempTask.getStatus().contentEquals(TasksListActivity.STATUS_IN_PROGRESS))
{
newmarker = map.addMarker(new MarkerOptions().position(latlng).title(tempTask.getTitle()).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_for_map_bordo)));
}
else if (tempTask.getStatus().contentEquals(TasksListActivity.STATUS_ON_THE_WAY))
{
newmarker = map.addMarker(new MarkerOptions().position(latlng).title(tempTask.getTitle()).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_for_map_turkiz)));
}
else if (tempTask.getStatus().contentEquals(TasksListActivity.STATUS_COMPLETE))
{
newmarker = map.addMarker(new MarkerOptions().position(latlng).title(tempTask.getTitle()).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_for_map_orange)));
}
else if (tempTask.getStatus().contentEquals(TasksListActivity.STATUS_FAILED))
{
newmarker = map.addMarker(new MarkerOptions().position(latlng).title(tempTask.getTitle()).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_for_map_purpul)));
}
}
See if it's helps you.
The if statements are for changing the marker icon.
The following snippet does the trick for me without dependencies:
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE);
myMap.addMarker(new MarkerOptions()
.position(point)
.icon(bitmapDescriptor)
.title(point.toString()));
Found it here: http://android-er.blogspot.de/2013/01/change-marker-color-of-googlemaps-v2.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With